| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1207 人关注过本帖
标题:拜托拜托大神光临。
只看楼主 加入收藏
zflovedota
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2017-6-12
结帖率:50%
收藏
 问题点数:0 回复次数:0 
拜托拜托大神光临。
解决问题,给答案,不要随便应付,谢谢。
题目描述
Do you know the famous Josephus Problem? There are n people standing in a circle waiting to be executed. The counting out begins at the first people in the circle and proceeds around the circle in the counterclockwise direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller and smaller as the executed people are removed), until only the last person remains, who is given freedom.

In traditional Josephus Problem, the number of people skipped in each round is fixed, so it's easy to find the people executed in the i-th round. However, in this problem, the number of people skipped in each round is generated by a pseudorandom number generator:

x[i+1] = (x[i] * A + B) % M.

Can you still find the people executed in the i-th round?


输入
There are multiple test cases.

The first line of each test cases contains six integers 2 ≤ n ≤ 100000, 0 ≤ m ≤ 100000, 0 ≤ x[1], A, B < M ≤ 100000. The second line contains m integers 1 ≤ q[i] < n.


输出
For each test case, output a line containing m integers, the people executed in the q[i]-th round.


样例输入
2 1 0 1 2 3
1
41 5 1 1 0 2
1 2 3 4 40

样例输出
1
2 4 6 8 35

搜索更多相关主题的帖子: direction becoming waiting person people 
2017-06-13 10:33
快速回复:拜托拜托大神光临。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015942 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved