题目描述
求矩阵幂
输入:矩阵维度n,矩阵幂m
输入:n阶矩阵
样例
2 2
9 8
9 3
算法1
n,m=map(int,input().split())
lst=[list(map(int,input().split()))for i in range(n)]
lst_res=lst.copy()
if m>0:
for q in range(m-1):
lst_res_next = [[0 for l in range(n)] for g in range(n)]
for i in range(n):
for j in range(n):
for k in range(n):
lst_res_next[i][j]+=lst_res[i][k]*lst[k][j]
lst_res=lst_res_next.copy()
else:
lst_res = [[1 for l in range(n)] for g in range(n)]
for i in range(n):
for j in range(n):
print(lst_res [i][j],end=” “)
print()