×

# A problem with Marbles-Practice(Medium) problem.

 0 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! asked 17 Sep '18, 01:57 3★shubhsy 1 accept rate: 0%

 0 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 answered 17 Sep '18, 13:07 434●2●13 accept rate: 4% 1 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 :) (18 Sep '18, 03:23) shubhsy3★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,658
×2,476
×1,919
×558
×159
×112
×11

question asked: 17 Sep '18, 01:57

question was seen: 128 times

last updated: 18 Sep '18, 03:23