Number formed after K times repeated addition of smallest divisor of N | JavaScript program to find the Kth number formed after repeated addition of smallest divisor of N ; If N is even ; If N is odd ; Add smallest divisor to N ; Updated N is even ; Driver code
function FindValue ( N , K ) { if ( N % 2 == 0 ) { N = N + 2 * K ; } else { let i ; for ( i = 2 ; i < Math . sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) break ; } N = N + i ; N = N + 2 * ( K - 1 ) ; } document . write ( N + " " ) ; } let N = 9 ; let K = 4 ; FindValue ( N , K ) ;