Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => The-Vita-Sum ) Codevita Previous Questions | The Vita Sum | THE INQUISITIVE





The Vita Sum

LEVEL:Beginner

Description

Tom the cat is brushing up his Math skills. He has a bag containing N balls of different colors. Now Tom can randomly pick any even number of balls from the bag. Tom wants to find out the sum of all such combinations of balls that he can pull out from the bag. He can pull out at max K balls in one pick.

Input Format

First line contains two space separated numbers N and K
Constraints:
1. 0<=N,k<=10^14
2. N >= k

Output Format

The output is the sum of all the combinations of balls he can pull out modulo 10^9+7 i.e. (1000000007)


Example 1:

Input
4 4
Output
8
Example 2:

Input
8 3
Output
29
Example 3:

Input
100 20
Output
893497552

oops

Login to see Discussion




Approach

Here we are just following what is given in the question ,
that is from 0 to r we are calculating value of ncr and we are adding it to the answer and finally we are printing answer mod 10^9+7 as given in the question

for those who don't know what is nCr , it is combinations
here we are trying to select r thing from n

formula for this is n!/(r! * (n-r)!)

to calculate this we have written code below


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution