Check whether a number can be represented by the product of two squares | Java 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
import java . util . * ; class GFG { static boolean prodSquare ( int n ) { HashMap < Float , Float > s = new HashMap < Float , Float > ( ) ; for ( int i = 2 ; i * i <= n ; ++ i ) { s . put ( ( float ) ( i * i ) , ( float ) 1 ) ; if ( s . containsKey ( ( float ) n / ( i * i ) ) ) return true ; } return false ; } public static void main ( String [ ] args ) { int n = 25 ; if ( prodSquare ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }