This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from math import sqrt, floor | |
N = 100000000 | |
def is_palindrome(n): | |
return str(n) == str(n)[::-1] | |
def sum_list(n): | |
res = set() | |
for i in xrange(n - 1, 0, -1): | |
l = [x*x for x in xrange(i, n + 1)] | |
t = sum(l) | |
if t > N: | |
break | |
if is_palindrome(t): | |
res.add(t) | |
return list(res) | |
if __name__ == '__main__': | |
t = int(sqrt(N/2)) + 1 | |
l = [item for sublist in map(sum_list, xrange(2, t + 1)) for item in sublist] | |
print len(set(l)), sum(set(l)) |
Aucun commentaire:
Enregistrer un commentaire