# Matrix Multiplication

Jan 5th, 2022
627
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include<bits/stdc++.h>
2.
3. using namespace std;
4. typedef long long int ll;
5. //#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
6. #define pb push_back
7. #define mp make_pair
8. #define fi first
9. #define se second
10. #define gcd __gcd
11. #define getl(s) getline(cin, s);
12. #define setpre(x) fixed << setprecision(x)
13. #define mset(a) memset(a, 0, sizeof(a))
14. #define endl '\n'
15. const int N=200050,M=1000000007;
16. const ll INF=1e18+7;
17. vector<vector<ll> > matrix_mul(vector<vector<ll> >A,vector<vector<ll> >B){
18.     int n=A.size(),m=A[0].size(),mm=B[0].size();
19.     vector<vector<ll> >C(n,vector<ll>(mm,0));
20.     for(int i=0;i<n;++i){
21.         for(int j=0;j<mm;++j){
22.             for(int p=0;p<m;++p){
23.                 C[i][j]=(C[i][j]+(A[i][p]*B[p][j])%M)%M;
24.             }
25.         }
26.     }
27.     return C;
28. }
29. vector<vector<ll> >divide_and_conquer(vector<vector<ll> >A,ll k){
30.     if(k==1) return A;
31.     vector<vector<ll> >B;
32.     B=divide_and_conquer(A,k/2);
33.     if(k%2==0) return matrix_mul(B,B);
34.     return matrix_mul(matrix_mul(B,B),A);
35. }
36. int main(){
37.     ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
38. //    freopen(".inp","r",stdin);
39. //    freopen(".out","w",stdout);
40.     ll n,t;
41.     return 0;
42. }
43. /*
44. ==================================+
45. INPUT:                            |
46. ------------------------------    |
47.
48. ------------------------------    |
49. ==================================+
50. OUTPUT:                           |
51. ------------------------------    |
52.
53. ------------------------------    |
54. ==================================+
55. */