Check if a number can be represented as product of two positive perfect cubes | Function to check if N can be represented as the product of two perfect cubes or not ; Stores the perfect cubes ; Traverse the Map ; Stores the first number ; Stores the second number ; Search the pair for the first number to obtain product N from the Map ; If N cannot be represented as the product of the two positive perfect cubes ; Driver code
function productOfTwoPerfectCubes ( N ) { let cubes = new Map ( ) ; for ( let i = 1 ; i * i * i <= N ; i ++ ) cubes . set ( i * i * i , i ) ; for ( let [ key , value ] of cubes . entries ( ) ) { let firstNumber = key ; if ( N % key == 0 ) { let secondNumber = N / key ; if ( cubes . has ( secondNumber ) ) { document . write ( " " ) ; return ; } } } document . write ( " " ) ; } let N = 216 ; productOfTwoPerfectCubes ( N ) ;