Marbles Problem (nCr)

my code:

editorial:

both are almost the same but mine is giving error.
Please point out the mistake.

@Rhinorox
Add these two conditions in the staring of loop
if (k < 0 || k > n) {cout<<1<<endl; continue; }
if (n-k < k) k = n-k;
Also inside loop, ans should be
ans=ans*(n-i+1);
ans/=(i);

@Rhinorox
Here is the updated code https://ide.codingblocks.com/s/282009

How your code got AC? Let’s suppose extra case is take care of. So, your code get AC because of starting the denominator from β€œ1” instead of β€œk”. Am i correct?

@Rhinorox
yes exactly. mark this doubt as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.