Uniform Generator
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 22610 Accepted Submission (s): 8889
Problem descriptioncomputer simulations often require random numbers. One-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 would generate pseudo-random numbers (seed) between 0 and MOD-1. One problem with functions of this form was that they would 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 would generate the series of pseudo-random numbers 0, 3, 1, 4, 2 in a re Peating cycle. In this example, all of the numbers between and including 0 and MOD-1 would be generated every MOD iterations of the Functi On. Note this by the nature of the function to generate the same seed (x+1) every time seed (x) occurs means that if a function Would generate all the numbers between 0 and MOD-1, it'll generate pseudo-random numbers uniformly with every MOD Iterati Ons.
If STEP = + MOD =, the function generates the series 0, 5 (or any other repeating series if the initial SE Ed is other than 0). This is a poor selection of STEP and MOD because no initial seed would generate all of the numbers from 0 and MOD-1.
Your program would determine if choices of STEP and MOD would generate a uniform distribution of pseudo-random numbers.
Inputeach line of input would contain a pair of integers for STEP and MOD on that order (1 <= STEP, MOD <= 100000).
Outputfor each line of input, your program should print the STEP value right-justified in columns 1 through, the MOD V Alue right-justified in columns one through and either "good Choice" or "bad Choice" left-justified starting in column 2 5. The "good Choice" message should is printed when the selection of STEP and MOD would generate all the numbers between an D including 0 and MOD-1 when MOD numbers is generated. Otherwise, your program should print the message "Bad Choice". After the output test set, your program should print exactly one blank line.
Sample Input3 515 2063923 99999
Sample Output3 5 Good Choice Choice 63923 99999 Good Choice
#include <stdio.h>
#include <string.h>
int main ()
{
int n,m;
while (scanf ("%d%d", &n,&m)!=eof)
{
printf ("%10d%10d", n,m);
int a[100005],i,j,k,p,q,b[100005];
a[0]=0;
Memset (b,0,sizeof (b));
B[0]=1;
for (I=1; i<m; i++)
{
a[i]= (a[i-1]+n)%m;
b[a[i]]++;
if (b[a[i]]==2)
{
printf ("Bad choice\n\n");
Break
}
}
if (i==m)
printf ("Good choice\n\n");
}
return 0;
}
HDU 1014 Uniform Generator