Advertisement
a53

Zar1

a53
Jan 15th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #define MOD 1000000007
  3. #define LL long long int
  4. using namespace std;
  5. LL n;
  6. struct Mat
  7. {
  8. int mat[6][6];
  9. };
  10. Mat NullMat=
  11. {
  12. {
  13. {1,0,0,0,0,0},
  14. {0,1,0,0,0,0},
  15. {0,0,1,0,0,0},
  16. {0,0,0,1,0,0},
  17. {0,0,0,0,1,0},
  18. {0,0,0,0,0,1}
  19. }
  20. };
  21.  
  22. Mat InitMat=
  23. {
  24. {
  25. {0,1,0,0,0,0},
  26. {0,0,1,0,0,0},
  27. {0,0,0,1,0,0},
  28. {0,0,0,0,1,0},
  29. {0,0,0,0,0,1},
  30. {1,1,1,1,1,1}
  31. }
  32. };
  33.  
  34. Mat prod(Mat A,Mat B)
  35. {
  36. Mat C;
  37. for(int i=0;i<6;++i)
  38. for(int j=0;j<6;++j)
  39. {
  40. C.mat[i][j]=0;
  41. for(int k=0;k<6;++k)
  42. C.mat[i][j]=(1ULL*C.mat[i][j]+1ULL*A.mat[i][k]*B.mat[k][j]%MOD)%MOD;
  43. C.mat[i][j]%=MOD;
  44. }
  45. return C;
  46. }
  47.  
  48. Mat pwr(Mat A,LL n)
  49. {
  50. Mat R=NullMat;
  51. while(n)
  52. {
  53. if(n%2)
  54. R=prod(R,A);
  55. A=prod(A,A);
  56. n/=2;
  57. }
  58. return R;
  59. }
  60.  
  61. int main()
  62. {
  63. ios_base::sync_with_stdio(0);
  64. cin.tie(0);
  65. cout.tie(0);
  66. cin>>n;
  67. Mat C=pwr(InitMat,n);
  68. cout<<C.mat[5][5];
  69. return 0;
  70. }
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement