Array ( [0] => [1] => questions [2] => Strings [3] => The-Vita-Sum )
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.
First line contains two space separated numbers N and K
Constraints:
1. 0<=N,k<=10^14
2. N >= k
The output is the sum of all the combinations of balls he can pull out modulo 10^9+7 i.e. (1000000007)
4 4
8
8 3
29
100 20
893497552
Login to see Discussion
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.
Login to see Solution