# Author: Steven Carr # Last Edited: October 2021 # Calculates the Ramanujan number import stdio import sys # User input n = int(sys.argv[1]) # Set a to temporary value # Use four while loops, setting the parameters to what a, b, c and d # equal to output the sum of cubes # ensure a^3 + b^3 = c^3 + d^3 a = 1 while a*a*a <= n: b = a while (a*a*a)+(b*b*b) <= n: c = a + 1 while c*c*c <= n: d = c while (c*c*c) + (d*d*d) <= n: if (a*a*a) + (b*b*b) == (c*c*c) + (d*d*d): stdio.write(str(a*a*a + b*b*b) + ' = ') stdio.write(str(a) + '^3 ' + '+ ' + str(b) + '^3 = ') stdio.writeln(str(c) + '^3 ' + '+ ' + str(d) + '^3') d += 1 c += 1 b += 1 a += 1