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 program to test above
function prodSquare ( n ) { var s = new Map ( ) ; for ( var i = 2 ; i * i <= n ; ++ i ) { s . set ( i * i , 1 ) ; if ( s . has ( n / ( i * i ) ) ) return true ; } return false ; } var n = 25 ; if ( prodSquare ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;