You are not logged in. Please login at www.codechef.com to post your questions!

×

# medium level problem - Marbles SIGSEGV error

 0 for the problem Marbles : http://www.codechef.com/problems/MARBLES here is the code. But the problem is code chef is returning SIGSEGV error and i am unable to find out the problem in my code. So please tell me can my code be modified to fit the conditions of the question or do i have to think from a new perspective? here is the code: #include using namespace std; long long int C(int n,int r) { if(r==1) return n; if(n==r) return 1; long long int c=C(n-1,r)+C(n-1,r-1); return c; } int main() { int t; cin>>t; while(t--) { int n,r; cin>>n>>r; cout<

 1 You are using recursion may be due to stackoverflow you are getting this error. You should find a better efficient method for calculating nCr for given "n" and "r". You can further optimiz it . Posting code here but don't copy this code , try to understand it and then modify your code :) long long FindWays(int a,int b){ int n = a-1; int r = b-1,i=0; long long result=1; if (r > n/2) { r = n - r; } for (i = 0; i < r; i++) { result *= (n-i); result /= (i+1); } return result; } answered 06 Feb '14, 00:17 3.6k●13●35●55 accept rate: 10%
 0 I think chandan is right. . . answered 06 Feb '14, 09:57 0★rachgonz 1 accept rate: 0%
 0 I think RachGonz is right. . . answered 10 Dec '17, 19:43 118●6 accept rate: 7%
 0 I think codesniper99 is right. . . answered 11 Jan, 00:47 1●1 accept rate: 0%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

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,556
×1,901
×278
×1

question asked: 05 Feb '14, 23:18

question was seen: 1,981 times

last updated: 11 Jan, 00:48