I have a problem, let's say: Find all two pairs of numbers (x, y) and (z, t) such that x³ + y³ = z³ + t³ , where (x, y)! = (Z, t) and x³ + y³ <10000 .
Taking the cubic root of 10,000 yeilds 21.544 → rounded to 21, I got:
#include <iostream>
using namespace std;
int main() {
for( int x = 1; x <= 20; ++x ) {
for( int y = x + 1; y <= 21; ++y ) {
for( int z = x + 1; z <= y - 1; ++z ) {
for( int t = z; t <= y - 1; ++t ) {
if( x*x*x + y*y*y == z*z*z + t*t*t ) {
cout << x << ", " << y << ", " << z << ", " << t << endl;
}
}
}
}
}
return 0;
}
I know that this code could be optimized more, and this is what I am looking for. In addition, one of my friends told me that y may be x + 2 instead of x + 1, and I doubt it, because if x = 1, then we will never have y = 2, which in this case missed one possible solution.
Any thought?
source
share