-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path078_coin_partitions.py
46 lines (36 loc) · 974 Bytes
/
078_coin_partitions.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
"""
idea:
"""
import time
def main():
pentagonals = generate_pentagonals(100000)
partitions_ls = [1]
n = 1
while partitions_ls[-1] % 1000000 != 0:
t = 0
pen_ind = 0
count = 0
while n - pentagonals[pen_ind] >= 0:
if t == 0 or t == 1:
count += partitions_ls[n - pentagonals[pen_ind]]
else:
count -= partitions_ls[n - pentagonals[pen_ind]]
t += 1
t %= 4
pen_ind += 1
partitions_ls.append(count)
n += 1
print(partitions_ls[-1])
print('n', n-1)
def generate_pentagonals(n_max):
pentagonals = []
for i in range(1, n_max+1):
pentagonals.append(pentagonal(i))
pentagonals.append(pentagonal(-i))
return pentagonals
def pentagonal(n):
return int((3 * n**2 - n) / 2)
if __name__ == '__main__':
start_time = time.time()
main()
print("time:", time.time() - start_time)