Check whether a number can be represented by the product of two squares | C ++ implementation to Check whether a number can be represented by the product of two squares ; Function to check if there exist two numbers product of whose squares is n ; Initialize map ; Store square value in hashmap ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool prodSquare ( int n ) { unordered_map < float , float > s ; for ( int i = 2 ; i * i <= n ; ++ i ) { s [ i * i ] = 1 ; if ( s . find ( n / ( i * i ) ) != s . end ( ) ) return true ; } return false ; } int main ( ) { int n = 25 ; if ( prodSquare ( n ) ) cout << " Yes " ; else cout << " No " ; }