Show the pairs of numbers between 1 and 1000 whose sum of squares is a power third of any number, and the sum of their third powers is the square of some number. Do not use mathematical functions such as ..., sqrt, pow
Let's try it.
Show the pairs of numbers between 1 and 1000
for(int i = 0; i <= 1000; i++)
for(int j = i; j <= 1000; j++) // starting at i to not repeat pairs twice
whose sum of squares
for(int i = 0; i <= 1000; i++)
for(int j = i; j <= 1000; j++) // starting at i to not repeat pairs twice
{
int sumSquare = i * i + j * j;
is a power third of any number
for(int i = 0; i <= 1000; i++)
for(int j = i; j <= 1000; j++) // starting at i to not repeat pairs twice
{
int sumSquare = i * i + j * j;
bool found = false;
for(int k = 1; k * k * k <= sumSquare; k++) // inefficient
{
if (k * k * k == sumSquare)
{
found = true;
}
}
if (found)
{
cout << i << " " << j << " " << k << endl;
}
}
and so on... You'll need to add the third condition, you may need to deal with overflows, maybe use size_t
, and make it more efficient.
But that should give you the correct ideas...