Uva--350 (数学)
2014-06-11 13:59:56
题意&思路:简单题不多说。
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> using namespace std; int main(){ int s[10005],p[10005],Z,I,M,L,Case = 0; while(scanf("%d %d %d %d",&Z,&I,&M,&L) == 4){ if(Z == 0 && I == 0 && M == 0 && L == 0) break; memset(s,0,sizeof(s)); memset(p,0,sizeof(p)); s[L] = 1; p[L] = 1; for(int cnt = 2; ; ++cnt){ L = (Z * L + I) % M; if(s[L]){ printf("Case %d: %d\n",++Case,cnt - p[L]); break; } else{ s[L] = 1; p[L] = cnt; } } } return 0; }