Page 1 of 8
10323 - Factorial! You Must be Kidding!!!
Posted: Sat Jul 06, 2002 7:09 pm
by yahoo
The problem seemed to be very much easy to me. But i can't understand why i am getting wrong answers. Can any body help me with some typical input.Here is my code:
#include<stdio.h>
#include<math.h>
#include<string.h>
main()
{
int i,r,j,n;
double x,v;
char a[10],b[10];
while(1)
{
n=0;
r=scanf("%s",a);
if(r==EOF) break;
for(i=0;i<strlen(a);i++)
if(a>='1' && a<='9')
break;
n=0;
for(j=i;j<strlen(a);j++)
b[n++]=a[j];
v=0;
for(i=0;i<n;i++)
v=v+(b-'0')*pow(10,n-i-1);
if(v<8) printf("Underflow!\n");
else if(v>13) printf("Overflow!\n");
else
{
x=1;
for(i=2;i<=v;i++)
x=x*i;
printf("%.0lf\n",x);
}
}
return 0;
}
Posted: Sat Jul 06, 2002 7:47 pm
by 10153EN
I think you better have a look at a thread in the Real Time Clarification, which is about this problem.
This problem is not as easy and straightforward as you think~
Posted: Sun Jul 07, 2002 7:44 pm
by yahoo
I can't understand what do you mean by thread in real time clarification. Would you please explain?
Posted: Sun Jul 07, 2002 7:49 pm
by 10153EN
Quoted from the words of the problem setter:
When I did mathematics a lot factorial of negative numbers was a very interesting issue to me. If factorial(-1) is not infinity then why is
C(4,5) = 4!/((5!)(-1!)) = 0, have you ever thought it this way. I am getting many complains on this issue, some saying it is non standard, I ask u to think again as f(n)=n*f(n-1) can be written as f(n-1)=f(n)/n.
And the problem statement clearly says than you can manipulate that expression.
-Shahriar Manzoor
Posted: Sun Jul 07, 2002 8:34 pm
by Caesum
this problem is just completely stupid. what is it saying ? that f(-1)=f(0)/0 ???
the factorial function can be defined 'continuously' in terms of an integral - it is called the gamma function. the gamma function has poles at negative integers and is undefined.
Posted: Mon Jul 15, 2002 4:37 pm
by LawrenceT
well... i guess the answers are quite obvious for positive input... well... when input is -1, f(-1) = f(0) / 0 = 1 / 0 = positive infinity (overflow)... den when u divide that by a negative num... u get another answer... and when u divide that by another negative num... what do you get?... that's the general idea... don't wanna give away too much

Posted: Mon Jul 15, 2002 5:50 pm
by xenon
f(-1) is just undefined, period. It's not infinity, gogolplex, or anything; just undefined, period. That's because the factorial function f(n) is only defined for n={0,1,2,3,...}.
The reasoning that f(-1) should be infinity, because C(4,5) should be 0 is faulty, because C(4,5) is undefined, not zero. It is impossible to pick 5 things out of 4, and that's something else then saying that there are zero ways.
All attempts to assign values to f(n) for negative n, are stupid layman's tricks, based on dividing out zeroes, manipulating infinity, etc. As stated before: f(n) simply doesn't exist for negative n.
A very angry,
-xenon
Posted: Mon Jul 15, 2002 6:30 pm
by LawrenceT
yes, i totally agree with you... the problem really has no mathematical basis... but anyway, the thing i stated earlier is just the solution
Posted: Tue Jul 16, 2002 5:12 am
by dh3014
indeed...by definition
f(-1) = 1 / 0 should be NaN instead of Inf
lim 1 / n is Inf
n->0+
Posted: Tue Jul 16, 2002 8:59 pm
by Joe Smith
xenon wrote:f(-1) is just undefined, period. It's not infinity, gogolplex, or anything; just undefined, period. That's because the factorial function f(n) is only defined for n={0,1,2,3,...}.
The reasoning that f(-1) should be infinity, because C(4,5) should be 0 is faulty, because C(4,5) is undefined, not zero. It is impossible to pick 5 things out of 4, and that's something else then saying that there are zero ways.
All attempts to assign values to f(n) for negative n, are stupid layman's tricks, based on dividing out zeroes, manipulating infinity, etc. As stated before: f(n) simply doesn't exist for negative n.
A very angry,
-xenon
That depends on your definition of C(n,k). If you take C(n,k) to be the coefficient of x^k in (1+x)^n, which is usually the definition I assume, then C(4,5) is indeed 0. And since choosing 5 things out of 4 can't be done, clearly the number of ways of doing so is not undefined, but 0. On the other hand, choosing -1 things out of 4, that would be undefined I suppose.
Anyway, bringing C(n,k) has NOTHING to do with the definition of n! so I don't even know why it was mentioned... that just makes Shahriar's explanation make even less sense. The value of C(4,5) has nothing to do with how f(-1) is defined, it's just 0.
Posted: Fri Jul 26, 2002 8:41 am
by ..
Someone already writes the answer in ranking.
Try to read the ranking before posting question.......
Posted: Wed Sep 25, 2002 3:49 am
by Fernandez Jose
well now i'm discovering a new impresive mathematics.
As it was said you can handle this problem in this way: f(n)=nf(n-1)=> f(n-1)=f(n)/n, lets see.
So to handle f(-1) we do f(0)=0f(-1),(this will always be cero, if f(-1)#oo).
As is defined f(0)=1
then f(-1)=1/0=+oo
this solution must verify de ecuation, as result
f(0)=1=0*oo (this is a great discovering for me)
In any case if the factorial function is named then it sould be a factorial not a extraneus function to puzzle people.
I'm for to change the name of the problem.
Posted: Wed Oct 02, 2002 3:37 pm
by yatsen
What is wrong with this easy problem?
Have any trap?
10323
Posted: Sun Oct 06, 2002 6:37 pm
by speciale
why its wrong?
#include <stdio.h>
int main ()
{
unsigned n=0;
while ( scanf("%u", &n) != EOF ) {
if (n < 13)
if (n >=

{
switch (n) {
case 8: printf("%lu\n",40320); break;
case 9: printf("%lu\n",362880); break;
case 10: printf("%lu\n",3628800); break;
case 11: printf("%lu\n",39916800); break;
case 12: printf("%lu\n",479001600); break;
/* case 13: printf("%lu\n",6227020800); break; */
}
}
else printf("Underflow!\n");
else printf("Overflow!\n");
}
return 0;
}[/c]
Posted: Sun Oct 06, 2002 8:16 pm
by ..
PLEASE READ OTHER POST IN THE FORUM BEFORE POST.
Just a few posts below, there is a long thread talking about this problem.