Codeforces Round #257 (Div. 2), problem: (B) Jzzhu and Sequences editorial: http://codeforces.com/blog/entry/13112
Codeforces Round #257 (Div. 2), problem: (B) Jzzhu and Sequences solution: http://ideone.com/Eh6hpS
#include <iostream> #include <cstdio> using namespace std; int main() { long long int x, y, z, n, tmp, a[7]={0}, ans; const int md=1e9+7; scanf("%I64d%I64d", &x, &y); scanf("%I64d", &n); z=y-x, a[1]=x, a[2]=y; for(int i=3; i<=6; i++) { tmp=x, x=y, y=z, z=y-x, a[i%6]=y; } if(a[n%6]>=0) printf("%I64d", a[n%6]%md); else printf("%I64d", (md+a[n%6]%md)%md); return 0; }
note: to learn about mod operation on negative numbers: http://math.stackexchange.com/questions/519845/modulo-of-a-negative-number
No comments:
Post a Comment