Pagini recente » Cod sursa (job #2067017) | Cod sursa (job #2483901) | Cod sursa (job #2424387) | Cod sursa (job #588774) | Cod sursa (job #600269)
Cod sursa(job #600269)
#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);
// printf("%d\n",l);
if(n>0)
for(n%=l;n>=0;t0=f(t0),--n)
if(!n)
sol=t0.f;
printf("%d\n",sol);
return 0;
}