Pagini recente » Cod sursa (job #1235273) | Cod sursa (job #3269692) | Cod sursa (job #1430500) | Cod sursa (job #2549800) | Cod sursa (job #68278)
Cod sursa(job #68278)
Utilizator |
Adrian Diaconu DITzoneC |
Data |
27 iunie 2007 13:52:41 |
Problema |
Rsir |
Scor |
Ascuns |
Compilator |
cpp |
Status |
done |
Runda |
|
Marime |
0.84 kb |
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long lint;
#define mp make_pair
#define PII pair <int,int>
#define f first
#define s second
#define nmax 1<<14
int t0,t1,a,b,x,y,z,m,sol;
int A[nmax],B[nmax];
lint n;
PII f(PII t)
{
int a=A[t.f]+B[t.s];
if(a>=m)
a-=m;
return mp(t.s,a);
}
int main()
{
PII t0,t1;
int l,i;
freopen("rsir.in","r",stdin);
freopen("rsir.out","w",stdout);
scanf("%d %d %d %d %d %d %d %d %lld",&t0.f,&t0.s,&a,&b,&x,&y,&z,&m,&n);
for(i=0;i<m;++i)
{
A[i]=((((i*i)%m)*a)%m+(((i)%m)*x)%m)%m;
B[i]=((((i*i)%m)*b)%m+(((i)%m)*y+z)%m)%m;
}
t0.f%=m, t0.s%=m;
t1=f(t0);
for(t1=f(t0);n>=0&&t1!=t0;t0=f(t0),t1=f(f(t1)),--n)
if(!n)
sol=t0.f;
for(l=1,t1=f(t0);n>=0&&t1!=t0;t1=f(t1),++l);
if(n>0)
for(n%=l;n>=0;t0=f(t0),--n)
if(!n)
sol=t0.f;
printf("%d\n",sol);
return 0;
}