Sylvester 's sequence | Python Code for Sylvester sequence ; To store the product . ; To store the current number . ; Loop till n . ; Driver program to test above function
def printSequence ( n ) : NEW_LINE a = 1 NEW_LINE ans = 2 NEW_LINE INDENT N = 1000000007 NEW_LINE i = 1 NEW_LINE while i <= n : NEW_LINE INDENT print ans , NEW_LINE ans = ( ( a % N ) * ( ans % N ) ) % N NEW_LINE a = ans NEW_LINE ans = ( ans + 1 ) % N NEW_LINE i = i + 1 NEW_LINE DEDENT DEDENT n = 6 NEW_LINE printSequence ( n ) NEW_LINE