Advertisement
Finnit

onibus

Jan 25th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define MILL 1000000
  6.  
  7. unsigned long long n, k, l;
  8.  
  9. struct matrix {
  10.         long long a, b, c, d;
  11. };
  12.  
  13. matrix matMul(matrix A, matrix B) {
  14.         matrix ans;
  15.         ans.a = (A.a*B.a+A.b*B.c) % MILL;
  16.         ans.b = (A.a*B.b+A.b*B.d) % MILL;
  17.         ans.c = (A.c*B.a+A.d*B.c) % MILL;
  18.         ans.d = (A.c*B.b+A.d*B.d) % MILL;
  19.         return ans;
  20. }
  21.  
  22. matrix fastMatPow(matrix m, long long p) {
  23.         if(p == 0) {
  24.                 matrix ans;
  25.                 ans.a = 1;
  26.                 ans.b = 0;
  27.                 ans.c = 0;
  28.                 ans.d = 1;
  29.                 return ans;
  30.         }
  31.         if(p % 2 == 0)
  32.                 return fastMatPow(matMul(m,m),p/2);
  33.         else
  34.                 return matMul(m,fastMatPow(matMul(m,m),p/2));
  35. }
  36.  
  37. int main(void) {
  38.         for(;;) {
  39.                 if(scanf("%Lu%Lu%Lu",&n,&k,&l) == EOF)
  40.                         break;
  41.                 matrix m;
  42.                 m.a = k % MILL;
  43.                 m.b = l % MILL;
  44.                 m.c = 1;
  45.                 m.d = 0;
  46.                 m = fastMatPow(m,n/5);
  47.                 printf("%.06Ld\n",m.a);
  48.         }
  49.         return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement