#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
int main()
{
ll Z, L, I, M, c, d = 0, i = 1;
while(cin >> Z >> I >> M >> L && Z > 0 && I > 0 && M > 0 && L > 0)
{
if(Z == I && I == M && M == L)
{
cout << "Case " << i++ << ": " << 1 << endl;
continue;
}
ll m = (Z*L+I)%M;
d = c = 0;
while(d != m)
{
if(c == 0)
{
ll p = (Z*m)%M;
d = (p+I)%M;
}
else
{
ll p = (Z*d)%M;
d = (p+I)%M;
}
c++;
}
cout << "Case " << i++ << ": " << c << endl;
}
return 0;
}
#define ll unsigned long long int
using namespace std;
int main()
{
ll Z, L, I, M, c, d = 0, i = 1;
while(cin >> Z >> I >> M >> L && Z > 0 && I > 0 && M > 0 && L > 0)
{
if(Z == I && I == M && M == L)
{
cout << "Case " << i++ << ": " << 1 << endl;
continue;
}
ll m = (Z*L+I)%M;
d = c = 0;
while(d != m)
{
if(c == 0)
{
ll p = (Z*m)%M;
d = (p+I)%M;
}
else
{
ll p = (Z*d)%M;
d = (p+I)%M;
}
c++;
}
cout << "Case " << i++ << ": " << c << endl;
}
return 0;
}
Comments
Post a Comment