Robert was surfing the internet recently, and found a reference to polygonal numbers. These are series such as the triangular numbers, pentagonal numbers and others, including the series of heptagonal numbers, which starts 1, 7, 18, 34…
Robert asked his nephew, Sam to tell him the next member of this series, which he said was 55. Later Sam told Robert that he had found a set of six consecutive heptagonal numbers, all less than two million, where the difference between the first and last was divisible by all of the digits 1 to 9. One of the intermediate heptagonal numbers in this set was divisible by just four of these digits.
What was this heptagonal number?
Note: Adapted from Enigma Number:1672 by Adrian Sommerfield, which appered in the New Scientist on 9 November, 2011.
Triangular numbers are generated by the sum: 1+2+3+4+...
Pentagonal numbers are generated by the sum: 1+4+7+10+...
Heptagonal numbers are generated by the sum: 1+6+11+16+...
which works out to (n/2)*(5n-3)
1, 7, 18, 34, 55, 81, 112, 148, 189
The 895th heptagonal number is 2001220 and is the first one that is over 2 million.
The set of 6 numbers is from the 401st to the 406th heptagonal numbers, but of these six, only the 405th is divisible by four digits.
n hept(n) #digits of divisibility
401 401401 2
402 403407 3
403 405418 2
404 407434 2
405 409455 4
406 411481 2
409455 is divisible by {1,3,5,9}
----------------------
def divtest(n):
""" int; number of digits 1 through 9 by which n is divisible """
ans = 0
for k in range(1,10):
if n%k == 0:
ans += 1
return ans
heptagonals = [int((n/2)*(5*n-3)) for n in range(0,895)]
for n in range(5,895):
diff = heptagonals[n] - heptagonals[n-5]
isdivisible = True
for k in range(2,10):
if diff%k != 0:
isdivisible = False
if not isdivisible:
continue
print(n)
lo = n-5
hi = n
for m in range(lo,hi+1):
print(m, heptagonals[m], divtest(heptagonals[m]))
|
Posted by Larry
on 2024-09-02 14:12:30 |