Uniform GeneratorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33660 Accepted Submission(s): 13368 http://acm.hdu.edu.cn/showproblem.php?pid=1014 Problem Description Computer simulations often require random numbers. One way to generate pseudo-random numbers is via a function of the form
Input Each line of input will contain a pair of integers for STEP and MOD in that order (1 <= STEP, MOD <= 100000).
Output For 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 Input 3 5 15 20 63923 99999
Sample Output 3 5 Good Choice
|
代码:
#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<cstdio>
#define inf 0x3f3f3f3f
using namespace std;
int main()
{
int step,mod;
int s[100005];
int num1,num2;
while(cin>>step>>mod)
{
memset(s,0,sizeof(s));
s[0]=0;
int sum=1;
for(int i=1;i<100000;i++)
{
s[i]=(s[i-1]+step)%mod;
if(s[i]==0)
break;
sum++;
}
printf("%10d%10d",step,mod);
if(sum==mod)
cout<<" Good Choice"<<endl<<endl;
else
cout<<" Bad Choice"<<endl<<endl;
}
return 0;
}