3 5 15 20 63923 99999
3 5 Good Choice 15 20 Bad Choice 63923 99999 Good Choice解题思路:这道题就是题目有点难懂,其实难度很小,就是产生伪随机数时给出的步长step和上限mod,判断下这两个值是否可以让产生的随机数均匀分布,所谓的均匀分布就是在step步里能产生出0到mod-1这mod个数。源代码:#include <stdio.h> #include <stdlib.h> int main() { int step,mod,seed,count; while(scanf("%d%d",&step,&mod)!=EOF) { seed=0,count=1; do { seed=(seed+step)%mod; count++; }while(seed!=0); count--; printf("%10d%10d ",step,mod); if(count==mod) printf("%s\n","Good Choice"); else printf("%s\n","Bad Choice"); printf("\n"); } system("pause"); return 0; }
原文地址:http://blog.csdn.net/zchlww/article/details/42609245