Hello, I just had a midterm and there was a question where we had to right a program which can calculate all the numbers which form quadruplets. A quadruplet would be

x^3+y^3+z^3=a^3
The program should only run till a<25 also,
0<x<y<z<a
at the end we had to output how many quadruplets exist and the number of comparisons we made. Can anyone please help me with an algorithm.
Thanks.

Recommended Answers

All 2 Replies

Hello, I just had a midterm and there was a question where we had to right a program which can calculate all the numbers which form quadruplets. A quadruplet would be

x^3+y^3+z^3=a^3
The program should only run till a<25 also,
0<x<y<z<a
at the end we had to output how many quadruplets exist and the number of comparisons we made. Can anyone please help me with an algorithm.
Thanks.

The brute force method would be to have four loops nested within each other and check each combination of the four variables and see if it's a quadruplet. That's the brute force method that doesn't attempt to find any type of optimization. It would be the simplest to write, I would imagine, but it would have a slow execution time.

n^3 + (3n^2+2^n+1)^3 + (3n^3+3n^2+2^n)^3 = (3n^3+3n^2+2^n+1)^3
In the above equation, put different value of n=1,2,3,4,...... and you get the quadruplets.
BUT remember that this was a short-cut which I gave you. You should know how this was derived. Currently I don't have enough time to explain it. Read:http://www.geocities.com/titus_piezas/RamCube.htm for a explanation.
Also, you should also Brute Force it, and check if it is feasible (It will be ;) )
Probably your teacher wants you to use Brute Force.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.