Number formed after K times repeated addition of smallest divisor of N | Python3 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 math NEW_LINE def FindValue ( N , K ) : NEW_LINE INDENT if ( N % 2 == 0 ) : NEW_LINE INDENT N = N + 2 * K NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 2 , ( int ) ( math . sqrt ( N ) ) + 1 ) : NEW_LINE INDENT if ( N % i == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT N = N + i NEW_LINE N = N + 2 * ( K - 1 ) NEW_LINE DEDENT print ( N ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 9 NEW_LINE K = 4 NEW_LINE FindValue ( N , K ) NEW_LINE DEDENT