Pagini recente » Cod sursa (job #1881976) | Cod sursa (job #2410893) | Cod sursa (job #2353610) | Cod sursa (job #2780420) | Cod sursa (job #1450758)
#include <cstdio>
FILE* in=fopen("rsir.in","r");
FILE* out=fopen("rsir.out","w");
int t0,t1,a,b,x,y,z,M;
long long n;
struct tipa
{
int f,g;
void operator =(const tipa &alta)
{
f=alta.f;
g=alta.g;
}
void operator ++()
{
long long act;
act=1LL*a*f*f+1LL*b*g*g+x*f+y*g+z;
act%=M;
f=g;
g=act;
}
} start;
bool operator ==(const tipa &una,const tipa &alta)
{
return (una.f==alta.f) & (una.g==alta.g);
}
void main2()
{
if(n<=60000000)
{
for(int i=1; i<n; i++)
++start;
fprintf(out,"%d",start.g);
return;
}
tipa iep,ste;
ste=start;
iep=start;
++iep;
while(!(ste==iep) )
{
++ste;
++iep;
++iep;
}
int l=1;
++iep;
while(!(ste==iep))
{
++iep;
l++;
}
iep=start;
ste=start;
for(int i=1; i<=l; i++)
++iep;
int bg=0;
while(!(ste==iep))
{
++iep;
++ste;
bg++;
}
int my=(n-bg) %l;
if(my==0)
my=l;
for(int i=1; i<my; i++)
++iep;
fprintf(out,"%d",iep.g);
}
int main()
{
fscanf(in,"%d%d",&t0,&t1);
fscanf(in,"%d%d",&a,&b);
fscanf(in,"%d%d%d",&x,&y,&z);
fscanf(in,"%d%lld",&M,&n);
start.f=t0%M;
start.g=t1%M;
main2();
return 0;
}