Number formed after K times repeated addition of smallest divisor of N | C ++ 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
#include <bits/stdc++.h> NEW_LINE #include <cmath> NEW_LINE using namespace std ; void FindValue ( int N , int K ) { if ( N % 2 == 0 ) { N = N + 2 * K ; } else { int i ; for ( i = 2 ; i < sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) break ; } N = N + i ; N = N + 2 * ( K - 1 ) ; } cout << N << endl ; } int main ( ) { int N = 9 ; int K = 4 ; FindValue ( N , K ) ; }