30 lines
524 B
Python
30 lines
524 B
Python
#!/usr/bin/env python3
|
|
|
|
def main(d):
|
|
tbl = [1]
|
|
n = 1
|
|
while p(n, tbl) % d: n+=1
|
|
return n, p(n,tbl)
|
|
|
|
def p(n, tbl=[1]):
|
|
if n < 0:
|
|
return 0
|
|
if n >= len(tbl):
|
|
r = -sum((-1)**i *
|
|
(p(n-a, tbl) +
|
|
p(n-b, tbl))
|
|
for a,b,i in pentnum(n))
|
|
tbl.append(r)
|
|
return tbl[n]
|
|
|
|
def pentnum(bound):
|
|
n = 1
|
|
a,b = 1,2
|
|
while a <= bound:
|
|
yield a,b,n
|
|
a += 3*n + 1
|
|
b += 3*n + 2
|
|
n += 1
|
|
|
|
print(main(10**6)[0])
|