import math
import sys
PROBLEM_RANGE = 10000
def brute():
count = 0
for a in range(2, PROBLEM_RANGE - 1, 3):
p, r = divmod(2*a - 1, 3)
D = int(a**2 + p**3)
for b in range(min(int(math.sqrt(D)), PROBLEM_RANGE - a), 0, -1):
if D % b**2 != 0:
continue
c = int(D/b**2)
if a + b + c <= PROBLEM_RANGE:
count += 1
if count % 100 == 0:
print(a, b, c)
return count
def main():
print(brute())
if __name__ == '__main__':
sys.exit(main())
Super slow and could not solve for large N.
2013年9月10日 星期二
ProjectEuler #251
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言