Page 7 of 8

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sat Oct 17, 2009 11:18 am
by sms.islam
code removed.After accepted!!!

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sun Oct 18, 2009 12:02 pm
by sms.islam
i got it!!! just precalculate the factorial.....oops its easy!!!

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Mon Aug 30, 2010 9:11 pm
by refat_ruet
can anyone help me...this code keep saying wrong answer..
#include<stdio.h>
long long int fact(long long int x);
long long por(long long int z);
int main(){
long long int n,z,y;
while(scanf("%llu",&n)==1){
z=fact(n);
y=por(z);
}

return 0;}
long long int fact(long long int x){
int i,s=1;
for(i=2;i<=x;i++)
s=s*i;
}
long long por(long long int z){
if(z>6227020800)
printf("Overflow!");
else if(z<10000)
printf("Underflow!") ;
else
printf("%llu",z);}

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sat Sep 04, 2010 8:35 am
by Jehad Uddin
Think about negative numbers and read previous posts.

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sun Jul 03, 2011 9:02 am
by plamplam
Lol this problem is indeed mathematically wrong. The factorial of negative integers are undefined according to the gamma function. The definition of the factorial function is:
(An example of a piece-wise defined function)
0! = 1
n! = n*(n-1)! for n > 0
I found in some previous posts that people said the factorial of 0 is 0....so the factorial of - 1 should be 0!/ 0. I am just writing this post for clarification.

First of all, note that 0! is not equal to 0. 0! = 1 (Check it out with your calculator :wink: ). The reason for this is demonstrated as below:
5! = 120
4! = 5! / 5
3! = 4! / 4
2! = 3! / 3
1! = 2! / 2
So, 0! = 1! / 1

An example of backtracking.

Another example:
nCk is the number of combinations possible you can choose k objects from a given set set of n objects.
By definition:
nCk = n! / (k! * (n - k)!)
So 0! = 1 neatly fits what we expect nC0 and nCn to be.

Also note that, before I give you the judge's logic(which is of course incorrect) for this problem, you must first understand the true logic. Anything divided by 0, Say 4 / 0 is NOT inifinity, rather it is not defined. That is why mathematicians refer to numbers that are divided by 0 as "undefined". (There is a special term for this called "indeterminate", search the web for more info) Some people tend to think of them as being infinite, but this isn't exactly true. There simply is no answer.

So We know that 0! = 1 now. We can use the same backtracking method to find -1!. Note again, that it is not possible to find factorials of negative numbers. By definition, -1! = 0! / 0
So, -1! = 1 / 0 = indeterminate
Again, -2! = -1! / -1 = indeterminate too(As -1! doesn't exist on the numerator, it follows that -2! also doesn't exist).

However the judge says that:
0! = 1 (True so this is an underflow)
-1! = 1 / 0 = +infinity = overflow (Wrong logic)
-2! = -1! / -1 = +infinity / -1 = -infinity = underflow(Again wrong logic!)
-3! = -2! / -2 = -infinity / -2 = + infinity = overflow......

I hope you understand now, why you need to check if n <= 0 then if (n % 2 == 0) = Underflow! and if (n % 2 != 0) = Overflow!
Note that this is mathematically and logically incorrect. This problem is just simply wrong(Wrong just because of the input contains negative numbers, if the dataset consisted of only positive numbers then the problem would be just fine)....its solution is wrong too. I just demonstrated the false logic which the judge uses.
Best Regards :) :wink:

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Mon Jul 25, 2011 9:41 pm
by anjanpstu
got accepted :) This is the most horror problem that I have ever solved.thank you online-judge.
but the code is simple after understanding

simply code the problem
only for n=8to n=13 value will be printed otherwise not
no need of thinking difficulty

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Wed Jul 27, 2011 4:47 pm
by plamplam
Actually, the most creepiest problem I have tried here is Problem no 139. This factorial :( problem is just illogical, that's all.

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sun Aug 21, 2011 12:57 am
by shoaib7k
remove code after accepted.....

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sun Aug 28, 2011 3:30 pm
by plamplam
Check these lines:

if(n%2==0)
printf("Underflow!\n");
else
printf("Overflow\n");
}

You forgot to include a factorial for Overflow.
It should be Overflow!

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Mon Aug 29, 2011 6:04 pm
by shoaib7k
thankssss/...... :)
got accepted......

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Tue Nov 08, 2011 9:10 pm
by Sultan_Dhaka
I can not understand what is the error in this code ?? Why is it not accepted ?? Hi guyz ! Please help me

#include<iostream>
using namespace std;

long int array[15];

void factorial(int N)
{
int i,result=1;
for( i=2;i<=N;i++)
result=result*i;
array[N]=result;
}

int main()
{
long int N;
for(int i=7;i<=14;i++)
factorial(i);
while(cin>>N)
{
if(N<0)
{
N=N*(-1);
if(N%2==1)
cout<<"Overflow!"<<endl;
else
cout<<"Underflow!"<<endl;
}
else if(N<8)
cout<<"Underflow!"<<endl;
else if(N>13)
cout<<"Overflow!"<<endl;
else
cout<<array[N]<<endl;

}
return 0;
}

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Thu Jun 07, 2012 8:34 pm
by what!
what is the wrong? please help.....


#include <stdio.h>


int main()
{
int n,i;
long long int sum;
while((scanf("%d",&n)==1))
{

sum=1;
if(n<8&&n>0)
printf("Underdflow!\n");
else if(n>13)
printf("Overflow!\n");

else if(n>=8&&n<=13)
{
for(i=n;i>=1;i--)
{
sum=sum*i;
}
printf("%lld\n",sum);
}
else if(n<=0)
{
if(n%2==0)
printf("Underflow!\n");
else
printf("Overflow!\n");
}
}

return 0;
}

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Fri Jun 08, 2012 1:03 am
by brianfry713
You misspelled Underflow

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Fri Jun 08, 2012 9:40 pm
by what!
brianfry713 wrote:You misspelled Underflow
Thanks. It is now AC.

Re: 10323 - Factorial! You Must be Kidding!!!

Posted: Sat Dec 01, 2012 9:25 pm
by akidsultan
i got wrong answer but i don't find my fault .......................
pls help me..............
here is my code.....

#include<stdio.h>
long long int fact(long long int n)
{
if(n==0)
return 1;
else
return (n*fact(n-1));
}
int main()
{
long long int a;
while(scanf("%lld",&a)!=EOF)
{
if(a<0&&a%2==1)
printf("Underflow!\n");
else if(a<0&&a%2==0)
printf("Overflow!\n");
else if(a==0||a<=7)
printf("Underflow!\n");
else if(a>13)
printf("Overflow!\n");
else
{
long long int i=fact(a);
printf("%lld\n",i);
}
}
return 0;
}