fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. /***template***/
  4. #define ll long long
  5. #define mat_size 3
  6. #define mod 1000000007
  7. long long mod1, col_num = mat_size, row_num = mat_size;
  8. long long mat[mat_size][mat_size], temp[mat_size][mat_size], res[mat_size][mat_size];
  9. void matpower(long long pwr)
  10. {
  11. long long i, j, k, s;
  12. if (pwr == 0)
  13. {
  14. for (i = 0; i < row_num; i++)
  15. {
  16. for (j = 0; j < col_num; j++)
  17. {
  18. if (i != j)
  19. res[i][j] = 0;
  20. else
  21. res[i][j] = 1;
  22. }
  23. }
  24. return ;
  25. }
  26. matpower(pwr/2);
  27. for (i = 0; i < col_num; i++)
  28. {
  29. for (j = 0; j < row_num; j++)
  30. {
  31. temp[i][j] = res[i][j];
  32. }
  33. }
  34. for (i = 0; i < col_num; i++)
  35. {
  36. for (j = 0; j < row_num; j++)
  37. {
  38. s = 0;
  39. for (k = 0; k < row_num; k++)
  40. s = (s + (temp[i][k]*temp[k][j])%mod)%mod;
  41. res[i][j] = s;
  42. }
  43. }
  44. if (pwr%2 == 1)
  45. {
  46. for (i = 0; i < row_num; i++)
  47. {
  48. for (j = 0; j < row_num; j++)
  49. {
  50. temp[i][j] = res[i][j];
  51. }
  52. }
  53. for (i = 0; i < row_num; i++)
  54. {
  55. for (j = 0; j < col_num; j++)
  56. {
  57. s = 0;
  58. for (k = 0; k < col_num; k++)
  59. s = (s + (mat[i][k]*(temp[k][j]))%mod)%mod;
  60. res[i][j] = s;
  61. }
  62. }
  63. }
  64. }
  65.  
  66. int main ()
  67. {
  68. mat[0][0] = 2;
  69. mat[0][1] = 2;
  70. mat[0][2] = 3;
  71. mat[1][0] = 2;
  72. mat[1][1] = 2;
  73. mat[1][2] = 4;
  74. mat[2][0] = 5;
  75. mat[2][1] = 5;
  76. mat[2][2] = 5;
  77. mod1=1000;// Jodi mod constant na hoi
  78. matpower(5);
  79. for(int i=0;i<mat_size;i++)
  80. {
  81. for(int j=0;j<mat_size;j++)
  82. {
  83. printf("%lld ",res[i][j]);
  84. }
  85. printf("\n");
  86. }
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0s 4380KB
stdin
Standard input is empty
stdout
25857  25857  33291  
30852  30852  39726  
52155  52155  67140