## 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

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
//-style comments are invalid in C.

If you submitted the code as C++, g++ could complain about the constant "6227020800".
Try writing it as "6227020800LL".

Salmin Sultana
New poster
Posts: 16
Joined: Sun Mar 07, 2004 12:19 pm
Location: Dhaka
we know fact(n)=nfact(n-1)
->fact(n-1)=fact(n)/n
->fact(n)=fact(n+1)/(n+1)

if n=-1 ,
-1!=fact(0)/0=infinity so overflow
if n=-2
-2!=fact(-1)/(-1)=-infinity so underflow

nd so on

ayeshapakhi
Learning poster
Posts: 60
Joined: Sun Apr 16, 2006 7:59 pm

### 10323 factorial u must kidding

Always the judge's reply is.... Compilation error.
Anyone pls pls help me fixing that;
here's my code:

Code: Select all

``````#include <stdio.h>
#include <math.h>

void main()
{
long long n,fact,i;

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

if( fact < 10000) printf("Underflow!\n");
else if (fact > 6227020800) printf("Overflow!\n");
else printf("%lld\n",fact);
}
}
else if(n == 0)	printf("Underflow!\n");
else
{
if( n > 13) printf("Overflow!\n");
else
{
fact=1;
for(i=n; i>=1; i--) fact*=i;

if( fact < 10000) printf("Underflow!\n");
else if (fact > 6227020800) printf("Overflow!\n");
else printf("%lld\n",fact);

}
}
}

}
``````
thanks.

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:
I think the problem of your code is this part :

Code: Select all

``````else if (fact > 6227020800) printf("Overflow!\n");
``````
Hope it helps...

sv90
New poster
Posts: 17
Joined: Wed Feb 01, 2006 8:27 pm

### 10323 WA >>>>NEED HELP

this is my code but idont know why i m getting wrong ans....
#include<stdio.h>

int main()
{

int i;
while((scanf("%d",&i))==1)
{
if(i<8)printf("Underflow!\n");
else if(i>13)printf("Overflow!\n");
else if(i==8)printf("40320\n");
else if(i==9)printf("362880\n");
else if(i==10)printf("3628800\n");
else if(i==11)printf("39916800\n");
else if(i==12)printf("479001600\n");
else if(i==13)printf("6227020800\n");
}

return 0;
}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
The problem's silly... you need to consider factorial of a negative integer. Usually it's just left undefined, but for this problem it can be +infinity (overflow) or -infinity (underflow). Guess, which is when.

anik
New poster
Posts: 4
Joined: Mon Aug 28, 2006 9:10 pm

### 10323 txt file missing

I am having peculiar prb while submiting 10323

when i try to submit code it says

There is 1 error:
* TEST FILES MISSING. The problem can't be judged
Uploaded source was NOT submitted

here is my code

Code: Select all

``````#include "stdio.h"

long long fact(long long x)
{
if(x==0||x==1)
return 1;
else
return x*fact(x-1);

}

void main()

{
long long n;
while (scanf("%lld",&n)!=EOF)
{
if(n<0){
n=-n;
if(n%2==0)
printf("Underflow!\n");
else
printf("Overflow!\n");
}
else{
if(n<8)
printf("Underflow!\n");
else if(n>13)
printf("Overflow!\n");
else
printf("%lld\n",fact(n));

}

}

}
``````
can anyone help me!!

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
You have to paste your in the 'source code' section, or you can upload your code. And another important thing. Dont open a new thread if there is one already.
Ami ekhono shopno dekhi...
HomePage

anik
New poster
Posts: 4
Joined: Mon Aug 28, 2006 9:10 pm
but i am still getting same error!!

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Oops my mistake. Goto volume 103. You will see that there is no tick mark for this problem. It means, the input file is missing or there is some problem. So, you cant submit it now. Check the problem after some time.
Ami ekhono shopno dekhi...
HomePage

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
Good.

This problem is plain wrong. Division by 0 is undefined, not +/- infinity. It is good to see that at least the judge admin is doing something about it.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

jainal cse du
New poster
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh
Why judge response WA,
I need help

Code: Select all

``````Code removed after AC.
``````
Last edited by jainal cse du on Sat Mar 31, 2007 11:23 am, edited 1 time in total.

abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Contact:
Hi,

For jainal- Are you sure your program gives the correct output? The output for 13 is not correct and it gives output also for n=14. But 13 is the upper limit by the program defination.

For n=13 the output should be 6227020800 and for n>13 it will be overflow. But your program gives wrong output for n=13 and also gives wrong for n>13.

There also a problem i can't understand in your code

Code: Select all

``````#define N 6227020800LL
``````
Why LL?

ABDULLAH

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
abdullah<cse du> wrote:

Code: Select all

``````#define N 6227020800LL
``````
Why LL?

ABDULLAH
LL indicates that number is type of "long long" in C (or C++) language..
So, no problem with that..

bishop
New poster
Posts: 43
Joined: Fri May 04, 2007 12:57 pm

### but why this is WA

plz help for WA

Code: Select all

``````
Code removed

``````

thanks
Last edited by bishop on Tue Jun 19, 2007 7:54 pm, edited 1 time in total.