Check whether a number can be represented by sum of two squares | A brute force approach based implementation to find if a number can be written as sum of two squares . ; function to check if there exist two numbers sum of whose squares is n . ; driver Program
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool sumSquare ( int n ) { for ( long i = 1 ; i * i <= n ; i ++ ) for ( long j = 1 ; j * j <= n ; j ++ ) if ( i * i + j * j == n ) { cout << i << " ^ 2 ▁ + ▁ " << j << " ^ 2" << endl ; return true ; } return false ; } int main ( ) { int n = 25 ; if ( sumSquare ( n ) ) cout << " Yes " ; else cout << " No " ; }