Pagini recente » Cod sursa (job #927051) | Cod sursa (job #1378173) | Cod sursa (job #1068125) | Cod sursa (job #2627891) | Cod sursa (job #1678867)
#include<fstream>
using namespace std;
ifstream fin("rsir.in");
ofstream fout("rsir.out");
long long L, n, a, b, x, y, z, mod, L1;
pair<long long,long long> A, B;
pair<long long,long long> next( pair<long long,long long> nr ){
pair<long long,long long> next_nr;
next_nr.first = nr.second;
next_nr.second = 1LL * a * nr.first * nr.first + 1LL * b * nr.second * nr.second + 1LL * x * nr.first + 1LL * y * nr.second + z;
next_nr.second %= mod;
return next_nr;
}
int main(){
fin >> A.first >> A.second >> a >> b >> x >> y >> z >> mod >> n;
A.first %= mod;
A.second %= mod;
a %= mod;
b %= mod;
x %= mod;
y %= mod;
z %= mod;
if( n == 0 ){
fout << A.first;
return 0;
}
if( n == 1 ){
fout << A.second;
return 0;
}
pair<long long,long long> save = A;
B = A;
do{
A = next( A );
B = next( next( B ) );
}while( A != B );
L = 0;
do{
L++;
B = next( B );
}while( A != B );
A = save;
B = save;
for( long long i = 1; i <= L; i++ ){
B = next(B);
}
L1 = 0;
while( A != B ){
A = next(A);
B = next(B);
L1++;
}
if( n < L1 ){
A = save;
for( long long i = 1; i <= n; i++ ){
A = next(A);
}
fout << A.first;
}else{
n = ( n - L1 ) % L;
for( long long i = 1; i <= n; i++ ){
A = next(A);
}
fout << A.first;
}
return 0;
}