Sunday, February 27, 2011

350 - Pseudo-Random Number


#include<iostream>
#include<stdlib.h>
using namespace std;
long int num[10000];
int main()
{
    long Z,I,M,L,seed=999,c,cas=0,i,j;
    //freopen("in.txt","r",stdin);
    while(cin>>Z>>I>>M>>L&&(Z|I|M|L))
    {
        seed=L;
        cas++;
        for(c=0;c<10000;c++)
        {
            L=(L*Z+I)%M;
            num[c]=L;
        }
        for(i=0;i<10000;i++)
            for(j=i+1;j<10000;j++)
                if(num[i]==num[j])
                {
                    c=j-i;
                    goto NEXT;
                }
NEXT:
        cout<<"Case "<<cas<<": "<<c<<endl;
    }
    exit(0);
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.