fork download
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5. int main() {
  6. long long int x, y, z, n, tmp, a[7]={0}, ans;
  7. const int md=1e9+7;
  8. scanf("%lld%lld", &x, &y);
  9. scanf("%lld", &n);
  10. z=y-x, a[1]=x, a[2]=y;
  11. for(int i=3; i<=6; i++) {
  12. tmp=x, x=y, y=z, z=y-x, a[i%6]=y;
  13. }
  14. if(a[n%6]>=0) printf("%lld", a[n%6]%md);
  15. else printf("%lld", (md+a[n%6]%md)%md);
  16. return 0;
  17. }
Success #stdin #stdout 0s 3300KB
stdin
7 -1000000000
3
stdout
Standard output is empty