Cod sursa(job #68997)

Utilizator anna_bozianuBozianu Ana anna_bozianu Data 30 iunie 2007 16:19:04
Problema Rsir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include<stdio.h>
long int t0,t1,t2,a,b,x,y,z,m,n,i,j,a1[7000],b1[7000],c[7000][7000];
int main()
{
	FILE *f,*g;
	f=fopen("rsir.in","r");
	g=fopen("rsir.out","w");
	fscanf(f,"%ld%ld",&t0,&t1);
	fscanf(f,"%ld%ld",&a,&b);
	fscanf(f,"%ld%ld%ld",&x,&y,&z);
	fscanf(f,"%ld%ld",&m,&n);
	t0=t0%m;t1=t1%m;
	for(i=0;i<m;i++)
	{ a1[i]=(a*i+x)%m;
	  a1[i]=(a1[i]*i)%m;
	  b1[i]=(b*i+y)%m;
	  b1[i]=(b1[i]*i+z)%m;
	}
	for(i=1;i<m;i++)
	 for(j=1;j<m;j++)
	  c[i][j]=(a1[i]+b1[j])%m;
	for(i=2;i<=n;i++)
	{
	     t2=c[t0][t1];
	     t0=t1;t1=t2;
	}
	fprintf(g,"%ld\n",t1);
	fcloseall();
	return 0;
}