# hdu 4965 Fast Matrix Calculation (矩阵快速幂，2014多校#9)

Step 2: Calculate M = C^(N*N).
Step 3: For each element x in M, calculate x % 6. All the remainders form a new matrix M’.
Step 4: Calculate the sum of all the elements in M’.

M = (A*B)^(N*N) = A * (B*A)^(N*N-1) * B