Find sum of product of number in given series | Python 3 program to find sum of product of number in given series ; function to calculate ( a ^ b ) % p ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 y = y / 2 ; function to return required answer ; modulo inverse of denominator ; calculating commentator part ; calculating t ! ; accumulating the final answer ; Driver Code ; function call to print required sum
MOD = 1000000007 NEW_LINE def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while y > 0 : NEW_LINE INDENT if y & 1 : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def sumProd ( n , t ) : NEW_LINE INDENT dino = power ( t + 1 , MOD - 2 , MOD ) NEW_LINE ans = 1 NEW_LINE for i in range ( n + t + 1 , n , - 1 ) : NEW_LINE INDENT ans = ( ans % MOD * i % MOD ) % MOD NEW_LINE DEDENT tfact = 1 NEW_LINE for i in range ( 1 , t + 1 ) : NEW_LINE INDENT tfact = ( tfact * i ) % MOD NEW_LINE DEDENT ans = ans * dino - tfact + MOD NEW_LINE return ans % MOD NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n , t = 3 , 2 NEW_LINE print ( sumProd ( n , t ) ) NEW_LINE DEDENT