yeputons

Untitled

Apr 17th, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. const int n = 2;
  2. struct Mat {
  3.   int m[n][n];
  4.   Mat(int x = 0) {
  5.     memset(m, 0, sizeof m);
  6.     for (int i = 0; i < n; i++) m[i][i] = x;
  7.   }
  8.   int* operator[](int y) { return m[y]; }
  9.   const int* operator[](int y) const { return m[y]; }
  10. };
  11. Mat operator*(const Mat &a, const Mat &b) {
  12.   Mat res;
  13.   for (int i = 0; i < n; i++)
  14.   for (int j = 0; j < n; j++) {
  15.     ll sum = 0;
  16.     for (int k = 0; k < m; k++)
  17.       sum += a[i][k] * b[k][j];
  18.     res[i][j] = sum % MOD;
  19.   }
  20.   return res;
  21. }
  22.  
  23. Mat a; ll b;
  24. Mat res = 1;
  25. for (; b; b >>= 1, a = a * a)
  26.   if (b & 1) res = res * a;
Add Comment
Please, Sign In to add comment