Pagini recente » Cod sursa (job #2033262) | Cod sursa (job #1748592) | Cod sursa (job #2932213) | Cod sursa (job #1478275) | Cod sursa (job #2237234)
#include<fstream>
#include<algorithm>
#include<ctime>
#include<iostream>
#include<bitset>
#include<unordered_map>
#define DN 7000
#define x first
#define y second
using namespace std;
ifstream fin("rsir.in");
ofstream fout("rsir.out");
int r1,r2,l,t0,t1,a,b,c,d,e,M,t2,t3,nr;
long long n;
unordered_map<long long,int>mp;
int main()
{
cout<<sizeof(mp)/1000;
fin>>t0>>t1>>a>>b>>c>>d>>e>>M>>n;
if(n==0)
{
fout<<t0;
return 0;
}
while(1)
{
nr++;
mp[1LL*1e4*t0+t1]=nr;
if(nr==n)
{
fout<<t1;
return 0;
}
t2=(1LL*a*((1LL*t0*t0)%M)+1LL*b*((1LL*t1*t1)%M)+1LL*c*t0+1LL*d*t1+e)%M;
t0=t1;
t1=t2;
auto it=mp.find(1LL*1e4*t0+t1);
if(it!=mp.end())
{
r1=t0;
r2=t1;
l=nr+1-it->y;
n-=it->y-1;
break;
}
}
n%=l;
if(n==0)
n=l;
nr=0;
while(1)
{
nr++;
if(nr==n)
{
fout<<t1;
return 0;
}
t2=(1LL*a*((1LL*t0*t0)%M)+1LL*b*((1LL*t1*t1)%M)+1LL*c*t0+1LL*d*t1+e)%M;
t0=t1;
t1=t2;
}
}