Program to find sum of the given sequence | Python3 program to find the sum of the given sequence ; function to find moudulo inverse under 10 ^ 9 + 7 ; Function to find the sum of the given sequence ; Driver code
MOD = 1000000007 ; NEW_LINE def modInv ( x ) : NEW_LINE INDENT n = MOD - 2 ; NEW_LINE result = 1 ; NEW_LINE while ( n ) : NEW_LINE INDENT if ( n & 1 ) : NEW_LINE INDENT result = result * x % MOD ; NEW_LINE DEDENT x = x * x % MOD ; NEW_LINE n = int ( n / 2 ) ; NEW_LINE DEDENT return result ; NEW_LINE DEDENT def getSum ( n , k ) : NEW_LINE INDENT ans = 1 ; NEW_LINE for i in range ( n + 1 , n - k , - 1 ) : NEW_LINE INDENT ans = ans * i % MOD ; NEW_LINE DEDENT ans = ans * modInv ( k + 1 ) % MOD ; NEW_LINE return ans ; NEW_LINE DEDENT n = 3 ; NEW_LINE k = 2 ; NEW_LINE print ( getSum ( n , k ) ) ; NEW_LINE