Cod sursa(job #73904)
#include<stdio.h>
long long int t0,t1,a,b,c,d,e,m,n,i,aux,term1[14000],term2[14000];
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);
fscanf(f,"%lld%lld%lld",&c,&d,&e);
fscanf(f,"%lld%lld",&m,&n);
a=a%m;b=b%m;
c=c%m;d=d%m;e=e%m;
t0=t0%m;
t1=t1%m;
term1[0]=e;
term1[m]=0;
for(i=1;i<m;i++)
{ term1[i]=(a*i*i+c*i+e)%m;
term2[i]=(b*i*i+d*i)%m;
term1[i+m]=term1[i];
term2[i+m]=term2[i];
}
for(i=1;i<=n;i++)
{ aux=term1[t0]+term2[t1];
t0=t1;
t1=aux;
}
t0=t0%m;
t1=t1%m;
fprintf(g,"%lld\n",t0);
fcloseall();
return 0;
}