HDOJ-1014 Uniform Generator

时间:2023-12-17 09:56:32

http://acm.hdu.edu.cn/showproblem.php?pid=1014

给出式子seed(x+1) = [seed(x) + STEP] % MOD

seed初始为0,给出STEP和MOD的值

问seed能否取到0~(MOD - 1)之间的所有值

简单模拟

# include <stdio.h>

int main()
{
int Step, Mod, i, Seed, Flag[100005]; while(scanf("%d %d",&Step, &Mod) != EOF)
{
for(i = 0; i <= Mod - 1; i++)
Flag[i] = 0; Seed = 0;
do
{
Flag[Seed] = 1;
Seed = (Seed + Step) % Mod;
}
while(Seed != 0); for(i = 0; i <= Mod - 1; i++)
if(Flag[i] == 0)
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;
}