Marbles wrong answer

c
c-plus-plus
code
codechef
gcc-432
practice

#1

Can anyone tell me where I went wrong in the Marbles problem? I dont see any fault in my Solution.


#2

Your solution is correct but the only problem is that value of comb() and the factorial() function which have defined are exceeding the range of long integers for larger values. The solution is always within the range of long64 so if you try to do the divide and multiply efficiently without going out of the range you would get the solution excepted. So efficient way of doing it linearly would be somewhat like this :

n C r can be found out by from n C 1 by multiplying (n-i) and dividing by (i+1) and going iteratively till i = r-1 starting from i = 1;