Skip to content

Instantly share code, notes, and snippets.

@ritsuca
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritsuca/07f47d9ad61bf96549ba to your computer and use it in GitHub Desktop.
Save ritsuca/07f47d9ad61bf96549ba to your computer and use it in GitHub Desktop.
# Python 2.7.5
# Q. How many are there integer sets to become a^4 + b^4 = c^4 + d^4 in the rage of 1 to 300
# There's an requirement: a < c < d < b
# create an array
# a = i[0], b = i[1], c = i[2], d = i[3]
i = [0,0,0,0]
# loop each number in 1..300
for i[0] in xrange (1,301):
for i[1] in xrange (1,301):
if i[1] > i[0]:
for i[2] in xrange (1,301):
if i[2] < i[1] and i[2] > i[0]:
for i[3] in xrange (1,301):
if i[3] > i[2]:
# calculate if there is an integer "x" or not: x = a^4 + b^4 = c^4 + d^4
x = (i[0]**4) + (i[1]**4) - (i[2]**4) - (i[3]**4)
# when find the "x", print the array "d"
if x == 0 :
print i
# below in Japanese
# [問題]
# a^2 + b^2 = c^2 + d^2 を満たす整数の組は,1〜100の範囲で多数ある。
# a^3 + b^3 = c^3 + d^3 を満たす整数の組,これもまぁまぁある。
# では, a^4 + b^4 = c^4 + d^4 を満たす整数の組は,1〜300の範囲でいくつあるか。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment