-
Notifications
You must be signed in to change notification settings - Fork 0
/
16.py
46 lines (37 loc) · 912 Bytes
/
16.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
from lib import *
input = read_input(2019, 16)
(*lst,) = map(int, input.strip())
n = len(lst)
for _ in range(100):
out = []
for i in range(n):
j = i
s = 0
while j < n:
for _ in range(i + 1):
if j >= n:
break
s += lst[j]
j += 1
j += i + 1
for _ in range(i + 1):
if j >= n:
break
s -= lst[j]
j += 1
j += i + 1
out.append(abs(s) % 10)
lst = out
print("".join(map(str, lst[:8])))
(*lst,) = map(int, input.strip())
offset = int("".join(map(str, lst[:7])))
lst = (lst * 10_000)[: offset - 1 : -1]
n = len(lst)
for _ in range(100):
out = []
s = 0
for i in range(n):
s = (s + lst[i]) % 10
out.append(s)
lst = out
print("".join(map(str, lst[:-9:-1])))