fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. int n, k;
  6. int mod = 1e9 + 7;
  7.  
  8. struct mtran
  9. {
  10. ll x[15][15];
  11. };
  12.  
  13. mtran z;
  14. mtran p;
  15.  
  16. mtran nhan(mtran a, mtran b)
  17. {
  18. mtran c;
  19. for(int i = 0; i < n; i++)
  20. {
  21. for(int j = 0; j < n; j++)
  22. {
  23. ll s = 0;
  24. for(int t = 0; t < n; t++)
  25. {
  26. s += (a.x[i][t] % mod * b.x[t][j] % mod) % mod;
  27. s %= mod;
  28. }
  29. c.x[i][j] = s;
  30. }
  31. }
  32. return c;
  33. }
  34.  
  35. int main() {
  36. ios_base::sync_with_stdio(0);
  37. cin.tie(0);
  38. cout.tie(0);
  39. int t; cin >> t;
  40. while(t--)
  41. {
  42. cin >> n >> k;
  43. for(int i = 0; i < n; i++)
  44. {
  45. for(int j = 0; j < n; j++)
  46. {
  47. cin >> z.x[i][j];
  48. }
  49. }
  50. p = z;
  51. for(int i = 1; i <= k - 1; i++)
  52. {
  53. p = nhan(p,z);
  54. }
  55. for(int i = 0; i < n; i++)
  56. {
  57. for(int j = 0; j < n; j++)
  58. {
  59. cout << p.x[i][j] << ' ';
  60. }
  61. cout << "\n";
  62. }
  63. }
  64. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  65. return 0;
  66. }
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty