Check whether a number can be represented as difference of two consecutive cubes | Function to print the two consecutive numbers whose difference is N ; Iterate in the range [ 0 , 10 ^ 5 ] ; Function to check if N is a perfect cube ; Find floating point value of square root of x . ; If square root is an integer ; Function to check whether a number can be represented as difference of two consecutive cubes ; Check if 12 * N - 3 is a perfect square or not ; Given Number N
function print ( N ) { for ( let i = 0 ; i < 100000 ; i ++ ) { if ( parseInt ( Math . pow ( i + 1 , 3 ) , 10 ) - parseInt ( Math . pow ( i , 3 ) , 10 ) == N ) { document . write ( i + " " + ( i + 1 ) ) ; return ; } } } function isPerfectSquare ( x ) { let sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function diffCube ( N ) { return isPerfectSquare ( 12 * N - 3 ) ; } let N = 19 ; if ( diffCube ( N ) != 0 ) { document . write ( " " + " " ) ; print ( N ) ; } else { document . write ( " " ) ; }