Program to find sum of the given sequence | Java 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
class GFG { static long MOD = 1000000007 ; static long modInv ( long x ) { long n = MOD - 2 ; long result = 1 ; while ( n > 0 ) { if ( ( n & 1 ) > 0 ) { result = result * x % MOD ; } x = x * x % MOD ; n = n / 2 ; } return result ; } static long getSum ( long n , long k ) { long ans = 1 ; for ( long i = n + 1 ; i > n - k ; i -- ) { ans = ans * i % MOD ; } ans = ans * modInv ( k + 1 ) % MOD ; return ans ; } public static void main ( String [ ] args ) { long n = 3 , k = 2 ; System . out . println ( getSum ( n , k ) ) ; } }