Problem Type : Number Theory
#include<stdio.h>
int main()
{
long long int Z, I, M, L,sum=0,count,l,i;
while(scanf("%lld %lld %lld %lld",&Z,&I,&M,&L)==4)
{
sum++;
if(Z==0 && I==0 && M==0 &&L==0)
{
return 0;
}
else
{
l=L;
count=0;
l=(Z*l+I)%M;
L=l;
for(i=0; ;i++)
{
l=(Z*l+I)%M;
count++;
if(l==L)
break;
}
}
printf("Case %lld: %lld\n",sum,count);
}
return 0;
}
#include<stdio.h>
int main()
{
long long int Z, I, M, L,sum=0,count,l,i;
while(scanf("%lld %lld %lld %lld",&Z,&I,&M,&L)==4)
{
sum++;
if(Z==0 && I==0 && M==0 &&L==0)
{
return 0;
}
else
{
l=L;
count=0;
l=(Z*l+I)%M;
L=l;
for(i=0; ;i++)
{
l=(Z*l+I)%M;
count++;
if(l==L)
break;
}
}
printf("Case %lld: %lld\n",sum,count);
}
return 0;
}
No comments:
Post a Comment