Min operations to reduce N by multiplying by any number or taking square root | Function to reduce N to its minimum possible value by the given operations ; Keep replacing n until is an integer ; Keep replacing n until n is divisible by i * i ; Print the answer ; Given N ; Function Call
function minValue ( n ) { while ( parseInt ( Math . sqrt ( n ) ) == Math . sqrt ( n ) && n > 1 ) { n = parseInt ( Math . sqrt ( n ) ) ; } for ( var i = parseInt ( Math . sqrt ( n ) ) ; i > 1 ; i -- ) { while ( n % ( i * i ) == 0 ) n /= i ; } document . write ( n ) ; } var N = 20 ; minValue ( N ) ;