Minimum divisor of a number to make the number perfect cube | Returns the minimum divisor ; Since 2 is only even prime , compute its power seprately . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; If count is not divisible by 3 , it must be removed by dividing n by prime number power . ; if n is a prime number ; Driven Program
function findMinNumber ( n ) { var count = 0 , ans = 1 ; while ( n % 2 == 0 ) { count ++ ; n /= 2 ; } if ( count % 3 != 0 ) ans *= Math . pow ( 2 , ( count % 3 ) ) ; for ( var i = 3 ; i <= Math . sqrt ( n ) ; i += 2 ) { count = 0 ; while ( n % i == 0 ) { count ++ ; n /= i ; } if ( count % 3 != 0 ) ans *= Math . pow ( i , ( count % 3 ) ) ; } if ( n > 2 ) ans *= n ; return ans ; } var n = 128 ; document . write ( findMinNumber ( n ) ) ;