bhupixb

Matrix Exponentiation

Jul 2nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
  5. const int mod = 1e9 + 7;
  6. #define int long long
  7. typedef vector < vector < int > > matrix;
  8.  
  9. inline int add(int x, int y) {
  10. return (x + y) % mod;
  11. }
  12.  
  13. inline int mul(int x, int y) {
  14. return (x * y) % mod;
  15. }
  16.  
  17. inline matrix mul(matrix v1, matrix v2) {
  18. vector< vector<int>> ans(2, vector<int> (2));
  19.  
  20. for (int i = 0; i < 2; ++i) {
  21. for (int j = 0; j < 2; ++j) {
  22. for (int k = 0; k < 2; ++k) {
  23. ans[i][j] = add(ans[i][j], mul(v1[i][k], v2[j][k]));
  24. }
  25. }
  26. }
  27. return ans;
  28. }
  29. matrix po(matrix cur, int n) {
  30. matrix res{
  31. {1, 0},
  32. {0, 1}
  33. };
  34. while (n) {
  35. if (n & 1) {
  36. res = mul(res, cur);
  37. }
  38. cur = mul(cur, cur);
  39. n >>= 1;
  40. }
  41. return res;
  42. }
  43.  
  44. signed main() {
  45. int t, a, b, n, cnt(0);
  46. cin >> t;
  47. vector < vector < int > > v{
  48. {1, 1},
  49. {1, 0}
  50. };
  51. while (t--) {
  52. cnt = 0;
  53. cin >> a >> b >> n;
  54. vector< vector<int>> cur(2, vector<int> (2));
  55. cur[0][0] = 1;
  56. cur[1][0] = 1;
  57. cur[1][1] = 0;
  58. cur[0][1] = 1;
  59.  
  60. }
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment