Skip to content

Instantly share code, notes, and snippets.

@pqcfox
Created January 31, 2015 20:52
Show Gist options
  • Select an option

  • Save pqcfox/a44ec1e150dfd8ec4eac to your computer and use it in GitHub Desktop.

Select an option

Save pqcfox/a44ec1e150dfd8ec4eac to your computer and use it in GitHub Desktop.
A program which finds all (a, b, c) in the positive integers such that a^3 + b^3 = c^2, given that c < 1225.
import math
a_list = []
b_list = []
c_list = []
c_max = 1225
a_max = int((c_max**2)**(1.0/3.0))
for c in range(1, c_max + 1):
for a in range(1, a_max + 1):
b_cubed = (c**2 - a**3)
if b_cubed <= 0: continue
b = int(round((c**2 - a**3)**(1.0/3.0)))
if a**3 + b**3 == c**2:
a_list.append(a)
b_list.append(b)
c_list.append(c)
for triple in zip(a_list, b_list, c_list):
print triple
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment