-
Notifications
You must be signed in to change notification settings - Fork 0
/
12850.py
51 lines (38 loc) · 1.01 KB
/
12850.py
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
45
46
47
48
49
50
51
from sys import stdin
input = stdin.readline
mod = 1_000_000_007
def mul_mat(a, b):
ret = [[0] * len(a) for _ in range(len(a))]
for i in range(len(a)):
for j in range(len(a)):
for k in range(len(a)):
ret[i][j] += a[i][k] * b[k][j]
ret[i][j] %= mod
return ret
def solve():
D = int(input())
mat = [[0, 1, 1, 0, 0, 0, 0, 0],
[1, 0, 1, 1, 0, 0, 0, 0],
[1, 1, 0, 1, 1, 0, 0, 0],
[0, 1, 1, 0, 1, 1, 0, 0],
[0, 0, 1, 1, 0, 1, 1, 0],
[0, 0, 0, 1, 1, 0, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 1],
[0, 0, 0, 0, 0, 1, 1, 0]
]
flag = True
bit = 1
while True:
if bit & D:
if flag:
ans = mat
flag = False
else:
ans = mul_mat(ans, mat)
if (bit << 1) > D:
break
mat = mul_mat(mat, mat)
bit <<= 1
return ans[0][0]
if __name__ == '__main__':
print(solve())