Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //matrix multiplication
- struct matrix {
- ll mat[6][6];
- matrix(){
- for(int i = 0;i<6;i++){
- for(int j = 0;j<6;j++)
- mat[i][j] = 0;
- }
- }
- };
- matrix mul(matrix &a,matrix &b){
- matrix res;
- for(int i = 0;i<6;i++){
- for(int j = 0;j<6;j++){
- for(int k = 0;k<6;k++){
- res.mat[i][j] += (a.mat[i][k] * b.mat[k][j])%M;
- res.mat[i][j] %= M;
- }
- }
- }
- return res;
- }
- matrix expo(matrix &base,ll power){
- if(power==1){
- return base;
- }
- if(power&1ll){
- matrix temp = expo(base,power-1);
- return mul(base,temp);
- }
- matrix temp = expo(base,power/2);
- return mul(temp,temp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement