10323 - Factorial! You Must be Kidding!!!

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sms.islam
New poster
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

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

Post by sms.islam » Sat Oct 17, 2009 11:18 am

code removed.After accepted!!!
Last edited by sms.islam on Sun Oct 18, 2009 12:04 pm, edited 1 time in total.

sms.islam
New poster
Posts: 19
Joined: Sat Oct 10, 2009 10:28 am

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

Post by sms.islam » Sun Oct 18, 2009 12:02 pm

i got it!!! just precalculate the factorial.....oops its easy!!!

refat_ruet
New poster
Posts: 3
Joined: Fri Aug 20, 2010 10:24 am

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

Post by refat_ruet » Mon Aug 30, 2010 9:11 pm

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);}

Jehad Uddin
Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

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

Post by Jehad Uddin » Sat Sep 04, 2010 8:35 am

Think about negative numbers and read previous posts.

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

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

Post by plamplam » Sun Jul 03, 2011 9:02 am

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:
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

anjanpstu
New poster
Posts: 7
Joined: Thu Apr 07, 2011 8:40 am

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

Post by anjanpstu » Mon Jul 25, 2011 9:41 pm

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

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

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

Post by plamplam » Wed Jul 27, 2011 4:47 pm

Actually, the most creepiest problem I have tried here is Problem no 139. This factorial :( problem is just illogical, that's all.
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

shoaib7k
New poster
Posts: 10
Joined: Thu Aug 18, 2011 7:45 pm

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

Post by shoaib7k » Sun Aug 21, 2011 12:57 am

remove code after accepted.....
Last edited by shoaib7k on Mon Aug 29, 2011 6:06 pm, edited 1 time in total.

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

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

Post by plamplam » Sun Aug 28, 2011 3:30 pm

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!
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

shoaib7k
New poster
Posts: 10
Joined: Thu Aug 18, 2011 7:45 pm

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

Post by shoaib7k » Mon Aug 29, 2011 6:04 pm

thankssss/...... :)
got accepted......

Sultan_Dhaka
New poster
Posts: 2
Joined: Wed Nov 02, 2011 8:26 am

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

Post by Sultan_Dhaka » Tue Nov 08, 2011 9:10 pm

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;
}

what!
New poster
Posts: 2
Joined: Thu Jun 07, 2012 7:53 pm

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

Post by what! » Thu Jun 07, 2012 8:34 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

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

Post by brianfry713 » Fri Jun 08, 2012 1:03 am

You misspelled Underflow
Check input and AC output for thousands of problems on uDebug!

what!
New poster
Posts: 2
Joined: Thu Jun 07, 2012 7:53 pm

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

Post by what! » Fri Jun 08, 2012 9:40 pm

brianfry713 wrote:You misspelled Underflow
Thanks. It is now AC.

akidsultan
New poster
Posts: 1
Joined: Sat Dec 01, 2012 9:12 pm

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

Post by akidsultan » Sat Dec 01, 2012 9:25 pm

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;
}

Post Reply

Return to “Volume 103 (10300-10399)”