Problem | Verdict | Lang | Time | Best | Rank | Submit Time |
---|---|---|---|---|---|---|
| discuss350 - | Accepted | C++11 | 0.000 | 0.000 | 886 | 1 mins ago |
Suggest:
-Note a[0] should is (z*l+i)%m not l beacause:
"But be careful: the cycle might not begin with the seed!"
#include<bits/stdc++.h>
using namespace std;
int z, i, m, l, test;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
while(cin >> z >> i >> m >> l && z && i && m && l){
vector<int> a(1,(z*l+i)%m);
do{
a.push_back((z*a.back()+i)%m);
}while(a[0] != a.back());
cout<<"Case "<<++test<<": "<<a.size()-1<<"\n";
}
}
No comments:
Post a Comment