Reach A and B by multiplying them with K and K ^ 2 at every step | function to check is it is possible to reach A and B starting from 1 and 1 ; find the cuberoot of the number ; divide the number by cuberoot ; if it is a perfect cuberoot and divides a and b ; Driver code
function possibleToReach ( a , b ) { let c = Math . cbrt ( a * b ) ; let re1 = a / c ; let re2 = b / c ; if ( ( re1 * re1 * re2 == a ) && ( re2 * re2 * re1 == b ) ) return true ; else return false ; } let A = 60 , B = 450 ; if ( possibleToReach ( A , B ) ) document . write ( " " ) ; else document . write ( " " ) ;