Euclidâ €“ Mullin Sequence | Function to return the smallest prime factor of n ; Initialize i = 2 ; While i <= sqrt ( n ) ; If n is divisible by i ; Increment i ; Function to print the first n terms of the required sequence ; To store the product of the previous terms ; Traverse the prime numbers ; Current term will be smallest prime factor of ( 1 + product of all previous terms ) ; Print the current term ; Update the product ; Find the first 14 terms of the sequence
def smallestPrimeFactor ( n ) : NEW_LINE INDENT i = 2 NEW_LINE while ( i * i ) <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return i NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return n NEW_LINE DEDENT def solve ( n ) : NEW_LINE INDENT product = 1 NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT num = smallestPrimeFactor ( product + 1 ) NEW_LINE print ( num , end = ' ▁ ' ) NEW_LINE product = product * num NEW_LINE i += 1 NEW_LINE DEDENT DEDENT b = 14 NEW_LINE solve ( b ) NEW_LINE