A problem with Marbles-Practice(Medium) problem.

Hi! I am facing a problem here. I submit the following code but it is getting accepted.

https://www.codechef.com/viewsolution/20202625

But, the following does not get accepted. All these both codes do is the same, calculate n-1Ck-1

https://www.codechef.com/viewsolution/20202600

What is the thing I am missing?

Thank You!

Because 2nd one is calculating ncr(n-1, k) instead of ncr(n-1, k-1)
Example for ncr(27,20) it should return 657800 i.e. N = 26 and K = 19
It is returning 230230 instead. i.e N = 26 and K = 20

Thank you for pointing that out.
That was due to me ignoring the case when the “if” statement is executed and the value of n is changed to n-r.
I removed it and changed it to n-r+1. It works fine now.
Thanks a lot.
Cheers :slight_smile:

1 Like