Modify N by adding its smallest positive divisor exactly K times | Function to find the smallest divisor of N greater than 1 ; If i is a divisor of N ; If N is a prime number ; Function to find the value of N by performing the operations K times ; If N is an even number ; Update N ; If N is an odd number ; Update N ; Driver Code
function smallestDivisorGr1 ( N ) { for ( var i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { return i ; } } return N ; } function findValOfNWithOperat ( N , K ) { if ( N % 2 == 0 ) { N += K * 2 ; } else { N += smallestDivisorGr1 ( N ) + ( K - 1 ) * 2 ; } return N ; } var N = 6 , K = 4 ; document . write ( findValOfNWithOperat ( N , K ) ) ;