Number formed after K times repeated addition of smallest divisor of N | Java 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
import java . util . * ; class GFG { static void FindValue ( int N , int K ) { if ( N % 2 == 0 ) { N = N + 2 * K ; } else { int i ; for ( i = 2 ; i < Math . sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) break ; } N = N + i ; N = N + 2 * ( K - 1 ) ; } System . out . print ( N ) ; } public static void main ( String args [ ] ) { int N = 9 ; int K = 4 ; FindValue ( N , K ) ; } }