Uniform Generator
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41700 Accepted Submission(s): 16391
Problem DescriptionComputer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form
seed(x+1) = [seed(x) + STEP] % MOD
where '%' is the modulus operator.
Such a function will generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form is that they will always generate the same pattern over and over. In order to minimize this effect, selecting the STEP and MOD values carefully can result in a uniform distribution of all values between (and including) 0 and MOD-1.
For example, if STEP = 3 and MOD = 5, the function will generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a repeating cycle. In this example, all of the numbers between and including 0 and MOD-1 will be generated every MOD iterations of the function. Note that by the nature of the function to generate the same seed(x+1) every time seed(x) occurs means that if a function will generate all the numbers between 0 and MOD-1, it will generate pseudo-random numbers uniformly with every MOD iterations.
If STEP = 15 and MOD = 20, the function generates the series 0, 15, 10, 5 (or any other repeating series if the initial seed is other than 0). This is a poor selection of STEP and MOD because no initial seed will generate all of the numbers from 0 and MOD-1.
Your program will determine if choices of STEP and MOD will generate a uniform distribution of pseudo-random numbers.
InputEach line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).
OutputFor each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either "Good Choice" or "Bad Choice" left-justified starting in column 25. The "Good Choice" message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message "Bad Choice". After each output test set, your program should print exactly one blank line.
Sample Input3 515 2063923 99999
Sample Output3 5 Good Choice15 20 Bad Choice63923 99999 Good Choice
题意:
seed(x + 1)= [seed(x)+ STEP]%MOD
这样一个函数 要求输入的STEP和MOD对任意的初始seed 生成0和MOD-1之间的所有数。
例如 如果STEP = 3 MOD = 5 则该函数将在重复循环中生成一系列伪随机数0,3,1,4,2。在这个例子中,所有在0和MOD-1之间(包括0和MOD-1)的数字将在函数的每个MOD迭代中生成。请注意,每次发生seed(x)时,通过函数的本质来生成相同的种子(x + 1)意味着如果一个函数将生成0到MOD-1之间的所有数字,则它将统一生成伪随机数每次MOD迭代。
如果STEP = 15且MOD = 20,则该函数会生成0,15,10,5系列(或者初始种子不是0的任何其他重复系列)。这是STEP和MOD的糟糕选择,因为没有初始种子会生成0和MOD-1中的所有数字。
你的程序将决定STEP和MOD的选择是否会产生伪随机数的均匀分布。
输入:
每行输入将按顺序包含STEP和MOD的一对整数(1 <= STEP,MOD <= 100000)。
输出:
对于每一行输入,你的程序应该在第1列到第10列右对齐地打印STEP值,在第11列到第20列右对齐的MOD值以及从列开始的左对齐“好选择”或“差选择” 25.当生成MOD编号时,如果选择STEP和MOD将生成0和MOD-1之间的所有数字,则应打印“良好选择”消息。否则,你的程序应该打印“不良选择”的消息。在每个输出测试集之后,您的程序应该只打印一个空白行。
思路:
虽然不知道为什么 但是这题其实是找到两个数的最大公约数如果是1,则为good choice! 反之,则是 bad choice! 但是不知道为什么就是找最大公约数
如果输入的两个数存在相同因子的话 一旦遇到seed(x)=0的情况 就会打乱原来固有规律 而后面生成的seed(x)就会变成他们因子的倍数。
但我不知道为什么。
ac代码:
#include<iostream>
int gcd(int a,int b)
{
if(a%b==0)
return b;
else
return gcd(b,a%b);
}
int main()
{
using namespace std;
int a,b;
while(cin>>a>>b)
{
printf("%10d%10d ",a,b);
if(a<b)
swap(a,b);
if(gcd(a,b)==1)
printf("Good Choice\n\n");
else
printf("Bad Choice\n\n");
}
}
通过本题不但发现自己英文太差 还发现读题能力也差 还发现自己辗转相除还是不够熟练。。