Problem solving with programming: Number of ways to represent an integer as sum of two squares
Given a number, we have to find out the number ways to express it in the form of sum of two integer squares.
For example let us consider 25, it can be written as sum of the pairs (0,25) (9,16)
Read full article from Problem solving with programming: Number of ways to represent an integer as sum of two squares
Given a number, we have to find out the number ways to express it in the form of sum of two integer squares.
For example let us consider 25, it can be written as sum of the pairs (0,25) (9,16)
bool isPerfectSquare(long a){long sqrtA = (long)sqrt(a*1.0);if( sqrtA*sqrtA == a )return true;return false;}
for(int i = 0; num-(i*i) > i*i ; i++ ){if( isPerfectSquare(num-i*i) ){cout << i*i << " " << (num-i*i) << endl;}}
Read full article from Problem solving with programming: Number of ways to represent an integer as sum of two squares