Program to find sum of the given sequence | Javascript 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
var MOD = 100000007 ; function modInv ( x ) { var n = MOD - 2 ; var result = 1 ; while ( n ) { if ( n & 1 ) result = result * x % MOD ; x = x * x % MOD ; n = n / 2 ; } return result ; } function getSum ( n , k ) { var ans = 1 ; for ( var i = n + 1 ; i > n - k ; i -- ) ans = ans * i % MOD ; ans = ans * modInv ( k + 1 ) % MOD ; return ans ; } var n = 3 , k = 2 ; document . write ( getSum ( n , k ) ) ;