I was watching "Futurama" reruns thue other day and in the episode "Lesser of Two Evils" it comes out that Flexo's and Bender's serial numbers are 3370318 and 2716057 respectively. Bender also says that both are expressible as a sum of two cubes.
So of course I had to write a program to find the cubes.
If A = B^3 + C^3, then either B^3 or C^3 must be no more than A/2. Assume B < C. Then B^3 <= A/2 so B <= cuberoot(A/2).
When you enter a number and click the Go button, the program loops variable B from 0 to cuberoot(A/2). (In Visual Basic, you can calculate the cube root or a number by taking the log of the number, dividing by 3, and then taking the exponent of the result.)
For each possible value B, the code calculates A - B^3 and takes the integer cube root to see what C would be. If C^3 exactly equals A - B^3, then we have a solution.
The program continues for other values of B to see if there are other solutions.
|