seed(x+1) = [seed(x) + STEP] % MOD
题目给STEP和MOD
然后问用这个公式是不是能产生所有0到MOD-1的数字
seed(0)=0
seed(x+1) = [seed(x) + STEP] % MOD
给你STEP,MOD,看对于上式是否seed(x)结果是否包括了0到MOD-1的所有值。
如果是,输出good choice 否则bad choice
附上代码仅供参考
#include
#define MAX 100000
int main(){
int Step,Mod;
int Seed[MAX];
int result[MAX],i;
while(scanf("%d",&Step)!=EOF&&scanf("%d",&Mod)!=EOF){
Seed[0] = 0;
for(i = 0; i<=Mod - 1 ;i ++){
Seed[i] = 0;
result[i] = 0;
}
for(i = 0 ; i <= Mod-1; i ++ ){
Seed[i+1] = (Seed[i] + Step) % Mod;
result[Seed[i+1]] =Seed[i+1];
}
for(i =1 ;i <= Mod-1; i ++){
if(i!=result[i])
break;
}
if(i <=Mod-1){
printf("%10d%10d Bad Choice\n\n",Step,Mod);
}else{
printf("%10d%10d Good Choice\n\n",Step,Mod);
}
}
return 0;
}