Mai intai trebuie sa te autentifici.
Cod sursa(job #2061027)
Utilizator | Data | 8 noiembrie 2017 21:13:09 | |
---|---|---|---|
Problema | Rsir | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 1.4 kb |
#include <bits/stdc++.h>
using namespace std;
int m;
long long n;
int a[7006], b[7006];
int x[7006], y[7006];
struct sir{
int t0, t1, a, b, x, y, z;
};
sir t, t2, e, aux;
inline void next(sir &tr){
int z = a[tr.t0] + b[tr.t1] + x[tr.t0] + y[tr.t1] + tr.z;
while(z >= m) z = z - m;
tr.t0 = tr.t1; tr.t1 = z;
}
int main(){
freopen("rsir.in", "r", stdin);
freopen("rsir.out", "w", stdout);
scanf("%d%d%d%d%d%d%d%d%lld", &t.t0, &t.t1, &t.a, &t.b, &t.x, &t.y, &t.z, &m, &n);
for(int i = 0; i <= m ; ++i) a[i] = ((1LL * i * i) % m * t.a) % m;
for(int i = 0; i <= m ; ++i) b[i] = ((1LL * i * i) % m * t.b) % m;
for(int i = 0; i <= m ; ++i) x[i] = (1LL * t.x * i) % m;
for(int i = 0; i <= m ; ++i) y[i] = (1LL * t.y * i) % m;
e = t; aux = t;
next(t); next(e); next(e);
while(!(t.t1 == e.t1 && t.t0 == e.t0)){next(t); next(e); next(e);}
int C = 1, L = 0, cr = 0;
next(t); next(e); next(e);
while(!(t.t1 == e.t1 && t.t0 == e.t0)){next(t); next(e); next(e); ++C;}
t = aux; t2 = aux; cr = C;
while(cr > 0) next(t2), --cr;
while(!(t.t1 == t2.t1 && t.t0 == t2.t0)){next(t); next(t2); ++L;}
t = aux;
if(n <= L) {
while(n > 0) next(t), --n;
}
else{
while(L > 0) {next(t); --n; --L;}
int w = n % C;
while(w > 0) next(t), --w;
}
printf("%d", t.t0);
return 0;
}