Climbing Stairs question (NZEC ERROR)

http://www.codechef.com/viewsolution/2414056 This code worked perfectly on my system, whereas here its giving runtime error(NZEC).

try this case…

1     //this is number of cases...though the sum says 10^5...this is just for checking!!!
1000000 2

this is giving divide by zero exception…maybe this is giving NZEC…hope this helps…:slight_smile:

@kunal361 : okay, understood whats going wrong. But i’m unable to debug it.

long counter=N;
		while(N>=0)
		{
			n1=(N/1);
			n2=(counter-n1)/2;
			N=N-2;
			temp1=fact(n1+n2);
			temp2=fact(n1)*fact(n2);
			ans=ans+(temp1/temp2);
		}

in this code fact() is finding the factorial. How to remove the division by zero exception. The fact() function is correct, then why with your specified inputs(for eg.), i’m getting this exception ?

I think there is stack overflow due to too many function calls of fact()…so u can try to memoize the fact values

@rahul_nexus : stack overflow can give “division by zero” exception ?
(just for knowing)

//