Hello,im trying to make a program that when you give it a number x it will output how many ways there are possible to get x by the sum of 2 powers(only powers that their base is raised by 2),if there are any.I will give an example so you can understand:
Input:50
1 2
Output:2
(there are 2 sums of powers that are equal to 50(i think so)(7^2+1^2 and 5^2+5^2))
@PopEye thanks for the help :),but as i saw it doesnt work with some numbers like 0 or 1 because 0 = 0^2 + 0^2 and 1 = 0^2 + 1^2.
I tried using a loop to check if any sums of all possible numbers raised by 2 are equal to 50, then add +1 to int ways.I dont know where the mistake is but here is my code:
#include <iostream>
#include <math.h>
usingnamespace std;
int main()
{
int x = 0, y = 0 , ways = 0 , a;
cout << "Enter Number:";
cin >> a;
int pow1 = pow(x,2) + pow(y,2);
for ( int i = 0 ; i < 11 ; i++ ){
if(pow1 != a){
int y = y + 1;
if (y == 10){
int y = y - 10;
int x = x + 1;
}
}
elseif(pow1 == a){
int ways = ways + 1;
}
}
if(ways >= 1){
cout << "/n Number Of Ways:" << ways << endl;
}
else{
cout << "No Ways Available!" << endl;
}
return 0;
}
This would check if any of the 110,possible sums of 2 powers raised by 2,between 0^2 +0^2 and 10^2 + 10^2,and then add +1 to ways if pow1 is equal to the input but it doesnt.Also this would only work for numbers smaller than 200(as 10^2+10^2=200).A bit complicated,isnt it?