Modify N by adding its smallest positive divisor exactly K times | Python 3 program to implement the above approach ; 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 ; Iterate over the range [ 1 , K ] ; Update N ; Driver Code
import math NEW_LINE def smallestDivisorGr1 ( N ) : NEW_LINE INDENT for i in range ( 2 , int ( math . sqrt ( N ) ) + 1 ) : NEW_LINE INDENT if ( N % i == 0 ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return N NEW_LINE DEDENT def findValOfNWithOperat ( N , K ) : NEW_LINE INDENT for i in range ( 1 , K + 1 ) : NEW_LINE INDENT N += smallestDivisorGr1 ( N ) NEW_LINE DEDENT return N NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 6 NEW_LINE K = 4 NEW_LINE print ( findValOfNWithOperat ( N , K ) ) NEW_LINE DEDENT