1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import sys n, b = map(int, sys.stdin.readline().rstrip().split()) arr = [] for _ in range(n): arr.append(list(map(int, sys.stdin.readline().rstrip().split()))) def mul(x, y): temp = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): temp[i][j] += x[i][k] * y[k][j] temp[i][j] %= 1000 return temp def pow(x, y): if y == 0: return u mid = pow(x, y // 2) if y % 2 == 0: return mul(mid, mid) else: return mul(x, mul(mid, mid)) def unit(x): temp = [[0] * x for _ in range(x)] for i in range(x): temp[i][i] = 1 return temp u = unit(n) arr = pow(arr, b) for i in range(n): for j in range(n): print(arr[i][j], end=‘ ‘) print() | cs |