Untitled

Jul 5th, 2022
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import numpy as np
2.
3. n = int(input())
4. ta, tb, tc = [int(_) for _ in input().split()]
5. pa, pb, pc = [int(_) for _ in input().split()]
6.
7. base_matrix = np.array(
8.     [
9.         [pa - 2, 1, 1],
10.         [1, pb - 2, 1],
11.         [1, 1, pc - 2],
12.     ],
13.     dtype="object",
14. )
15.
16. unit_matrix = np.array(
17.     [
18.         [1, 0, 0],
19.         [0, 1, 0],
20.         [0, 0, 1],
21.     ],
22.     dtype="object",
23. )
24.
25. MOD = 10**9 + 7
26.
27.
28. def pow_matrix(n):
29.     if n == 0:
30.         return unit_matrix
31.     elif n == 1:
32.         return base_matrix
33.     else:
34.         pow_2 = pow_matrix(n // 2)
35.         if n & 1:
36.             return np.dot(np.dot(pow_2, pow_2), base_matrix) % MOD
37.         else:
38.             return np.dot(pow_2, pow_2) % MOD
39.
40.
41. t_matrix = np.array(
42.     [
43.         [ta],
44.         [tb],
45.         [tc],
46.     ],
47.     dtype="object",
48. )
49.
50. res_matrix = np.dot(pow_matrix(n), t_matrix)
51.
52. print(*res_matrix)
53.