Sunday, August 17, 2014

uva : 350 - Pseudo-Random Numbers


#include<stdio.h>
#include<math.h>
int main()
{
    long Z,I,M,L,y=1;
    while(scanf("%ld %ld %ld %ld",&Z,&I,&M,&L)==4)
    {
        if((Z+I+M+L)==0)break;
        long i,j,k,l,m,n=0,num1[M+1];
        for(i=0;i<=M;i++)
        {
            num1[i]=0;
        }
        i=L;
        while(1)
        {
            i=(Z*i+I)%M;
            num1[i]++;
            if(num1[i]==2)break;
            n++;
        }
        printf("Case %ld: %ld\n",y++,n);
    }
    return 0;
}

No comments:

Post a Comment