Pentagonal numbers are generated by the formula,
It can be seen that
Find the pair of pentagonal numbers,
The goal is to find
The expression
The system of equations has the solution
from itertools import count
from sympy import divisors
from math import isqrt
def p44():
for d in count(1):
Pd2 = d * (3*d - 1)
for a in divisors(Pd2):
b = Pd2 // a
if b < 3 * a:
break
if b % 3 == 2:
c = (b + 1) // 3
if a % 2 == c % 2:
k = (a + c) // 2
j = (c - a) // 2
Pk2 = k * (3*k - 1)
Pj2 = j * (3*j - 1)
Ps2 = Pk2 + Pj2
if isqrt(1+12*Ps2)**2 == 1+12*Ps2 and (1 + isqrt(1 + 12*Ps2)) % 6 == 0:
return Pd2 // 2