这个题不算难,缺卡住了我
原因是我忽略了一句话,“But be careful: the cycle might not begin with the seed!”
原因是我忽略了一句话,“But be careful: the cycle might not begin with the seed!”
以后自己还得注意自己的细心!!!
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
int a[10000];
int main ()
{
long long int z, i, m, l, n = 0;
while(cin>>z>>i>>m>>l)
{
memset(a,0,sizeof(int)*10000);
n++;
if(!z&&!i&&!m&&!l)break;
int count = 0;
int j = l;
for(;;)
{
count++;
j = (z * j + i ) % m;
if(a[j] == 1)break;
else a[j] = 1;
}
int flag = 0;
for(int k = l;;)
{
flag++;
k = (z * k + i) % m;
if(k == j)
{
count-=flag;
break;
}
}
cout<<"Case "<<n<<": "<<count<<endl;
}
return 0;
}