Pagini recente » Istoria paginii runda/alabala | Cod sursa (job #1586793) | Istoria paginii runda/sadas/clasament | Cod sursa (job #478901) | Cod sursa (job #134955)
Cod sursa(job #134955)
#include<stdio.h>
long long int t0,t1,a,b,x,y,z,m,t2,n,i,p2,f0[7000],f1[7000],poz[7000][20],ppoz,per;
int main()
{
FILE *f,*g;f=fopen("rsir.in","r");g=fopen("rsir.out","w");
fscanf(f,"%lld%lld",&t0,&t1);
fscanf(f,"%lld%lld",&a,&b);
if(a+b==0){fprintf(g,"aaa\n");fcloseall();return 0;}
fscanf(f,"%lld%lld%lld",&x,&y,&z);
fscanf(f,"%lld",&m);
t0=t0%m;t1=t1%m;a=a%m;b=b%m;x=x%m;y=y%m;z=z%m;
for(i=0;i<m;i++){p2=(i*i)%m;f0[i]=(a*p2+x*i+z)%m;f1[i]=(b*p2+y*i)%m;}
for(;;)
{ t2=f0[t0]+f1[t1];if(t2>=m)t2-=m;t0=t1;t1=t2;ppoz++;
if(t1<20&&poz[t0][t1])break;
poz[t0][t1]=ppoz;
}
per=ppoz-poz[t0][t1];
if(n>ppoz)
{ n=n-ppoz;
n=n%per;
for(i=0;i<n;i++)
{t2=f0[t0]+f1[t1];if(t2>=m)t2-=m;t0=t1;t1=t2;}
fprintf(g,"%lld\n",t0);
fcloseall();
return 0;
}
else for(;;);
}