UVa 10323 - Factorial! You Must be Kidding!!!

Well it is defined for 8 f(-1) = f(0)/0 => + inf *Overflow * f(n-2) = f(n-1)/n-1 => +inf/-2 = -inf (underflow *this is undefined i think *) * You cannot play around with infinities as you like. I am not an expert on calculus. More interested ones should consult Apostol *define limits * and factorial. Well factorials are defined for every integer. But that is on http://mathworld.wolfram.com/Factorial.html. Also factorial is something like n* n-1* n-2 * n-3. Now if you apply that to -1 it would be -1 * -2 * -3 * - 4 * -5.... * -inf. Now is inf odd or even ? I think the author assumed even. My answer is it really isn't defined. Anyways have fun :) In case you just want to solve the problem below is the code. - temper3243@gmail.com

/* temper3243@gmail.com */ unsigned long long fact(int n) { int i;	unsigned long long prod=1ULL;
 * 1) include

if(n < 0) {		n=-n; if(n%2==0) return 1ULL; else return 0ULL; }	for(i=1;i<=n;i++) {		prod*=(unsigned long long )i; if(prod > 6227020800ULL) return 0ULL; }

if(prod < 10000) return 1ULL;

return prod;

}

int main {	int n;	unsigned long long k;	while(scanf("%d",&n)!=-1) {			k=fact(n); if(k==0) printf("Overflow!\n"); else if(k==1) printf("Underflow!\n"); else printf("%llu\n",k); }

return 0; }