Determine the smallest positive integer that can be expressed as the sum of three nonzero squares in five different ways.
Assuming that the 3 squares need not be distinct.
The smallest is:
194
[(1, 49, 144), (9, 16, 169), (9, 64, 121), (25, 25, 144), (49, 64, 81)]
-----------
from itertools import combinations_with_replacement
big = 15
sqs = [n**2 for n in range(1,big+1)]
sumof3squares = {}
for comb in combinations_with_replacement(sqs, 3):
mysum = sum(comb)
if mysum not in sumof3squares:
sumof3squares[mysum] = [comb]
else:
sumof3squares[mysum].append(comb)
winners = []
for k,v in sumof3squares.items():
if len(v) > 4:
winners.append(k)
winners = sorted(winners)
print(winners[0], sumof3squares[winners[0]])
|
Posted by Larry
on 2024-07-27 11:42:59 |