MPOW - Power of matrix
You will be given a square matrix M and a positive integer power N. You will have to compute M raised to the power N. (that is, M multiplied with itself N times.)
First line of input is T ( number of test-cases) First line of each test-case contains two integer M , N where M is size of square matrix that we have to exponent and N is the power to which we have to exponent
Next M lines describe the input matrix. Each line contains exactly M elements corresponding to each array
Output M line corresponding to each row of resultant matrix Each line must have M integers where jth element of ith line is jth element of resultant matrix taken modulo with 1000000007 (10^9+7).
Simply , you have to print the resultant square matrix.
Input:2 2 3 1 0 1 1 3 3 1 0 4 1 2 2 0 4 4
Output:1 0 3 1 17 112 116 15 88 100 28 144 160
0<=each element of input matrix<=10^9
if anyone is here after watching the CodeNcode video do this in multiplication operator :-
Can any one help me
i am getting tle in python . i used matrix exponentiation method.Last edit: 2020-09-12 01:07:38
0.07sec && 4.7MB
If you can't figure out why you are getting wa then use long long and use modular arithmetic wisely.
->If you are not able to build logic , see code Ncode video on matrix exponentiation.
after 4 days of thinking and getting lot of wa finally i come with a solution and it's accepted. codeNcode help a lot for this problem. but it's easy to think Matrix struct for this problem. its make sense to me.Last edit: 2020-07-16 09:51:12
I have followed all the suggestions from the comments but still I am getting WA
remember to use mod correctly gave me many WA.
where 1000000007 have to use ...i can't understand ....please help me