1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#include <iostream> #include <map> using namespace std; map<unsigned long long,int> mp; int main() { unsigned long long z,I,M,L; int c=0; while(cin>>z) { cin>>I>>M>>L; if(z==0 && I==0 && M==0 && L==0) break; c++; mp.clear(); L=((z)*(L)+I)%M; //mp[L]=1; while(mp[L]==0) { mp[L]=1; L=(z*L+I)%M; } cout<<"Case "<<c<<": "; cout<<mp.size()<<"\n"; } return 0; } |