Chapter 45
When Is The Next Centered Pentagonal Flag?
The 50 stars on the American flag form two rectangles because is twice a square, . With statehood proposed for Washington, D.C., a -star flag could place a star in the center surrounded by concentric pentagons of and stars, a centered pentagonal number. So has two nice properties at once: is twice a square and is a centered pentagonal number. After , what is the next integer with both properties?
The Riddler, FiveThirtyEight(original post)
Solution
We need and for integers . Eliminating , , so , and after completing the square () this becomes a Pell equation. Its fundamental solution is , and the rest come from powers of : The first solution gives , , . The next, , gives , , so with . (The one after that is .)
The computation
Scan the centered pentagonal numbers: for each , form and keep those for which is a perfect square (so is twice a square).
from math import isqrt
found = []
for p in range(1, 2000):
N = (5*p*p + 5*p) // 2 # N+1 is centered pentagonal
if (5*p*p + 5*p) % 2 == 0 and N % 2 == 0:
q2 = N // 2
if isqrt(q2)**2 == q2: # N = 2 * (perfect square)
found.append(N)
print(found[:3]) # [50, 16200, 5216450]