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

**Moderator:** Board moderators

- Ghust_omega
- Experienced poster
**Posts:**115**Joined:**Tue Apr 06, 2004 7:04 pm**Location:**Venezuela

Hi!!! Gazi Shaheen Hossain (again jeje ..) the reason for the compile error is that i is not a integer and, if you declare i as int you get not Compile error, WA but this is becase the input can be < 0 so in that case you have to see if n is odd or even, see the previos posted for get the information

Hope it Helps

Keep posting !!

Hope it Helps

Keep posting !!

### 10323 Why Wrong Ans.

/* Why This Code Gives W.A.? I Can't understand!! Please Help Me.*/

#include<stdio.h>

long fac[]={40320,362880,

3628800,39916800,

479001600};

long n,m;

int l;

int len(long n1);

void main()

{ long d=0;

while(1==scanf("%ld",&n))

{

if(n>999999)

break;

if(n<8)

printf("Underflow!\n");

else if(n==13)

printf("6227020800");

else if(n>13)

printf("Overflow!\n");

else

{

d=n-8;

printf("%ld\n",fac[d]);

}

}

}

#include<stdio.h>

long fac[]={40320,362880,

3628800,39916800,

479001600};

long n,m;

int l;

int len(long n1);

void main()

{ long d=0;

while(1==scanf("%ld",&n))

{

if(n>999999)

break;

if(n<8)

printf("Underflow!\n");

else if(n==13)

printf("6227020800");

else if(n>13)

printf("Overflow!\n");

else

{

d=n-8;

printf("%ld\n",fac[d]);

}

}

}

### 10323 factorial with negative numbers

i read the previous topics about this problem

are u sure i must handle negative numbers

if yes

how can i do this?

is there a factorial for negative numbers[/code]

are u sure i must handle negative numbers

if yes

how can i do this?

is there a factorial for negative numbers[/code]

As long as the input is not going to be changed you will have to.

Have you tried finding out the result on paper?You should get it, then how

to do it with your favourite programming language.One hint, and I will spoil the problem.Come back after you have tried, with your results, you'll get more help, if required.

Regards,

Suman.

PS:AFAIK factorial is defined for non-negative numbers, but then the problem

setter seems to have taken a little liberty with that definition and we have had posts blasting the same.

http://mathworld.wolfram.com/Factorial.html

However there are some extensions to the factorial function for real/complex numbers.You might want to read up on Gamma functions.

### 10323

i c that gama function represent the factorial for negative numbers

form this formula

F(z+1)= ((-1)^K)/k!

so if the input any negative integers the out put will underflow!(as i expect)

but its wrong answer

why????????????????????????????????????????????

form this formula

F(z+1)= ((-1)^K)/k!

so if the input any negative integers the out put will underflow!(as i expect)

but its wrong answer

why????????????????????????????????????????????

The P.S: section was for additional information not pertinent to the problem.

It was there should you be interested and would like to look aroung.

I have confused you more than I have helped you.

Anyway, coming back to the problem, the problem is way too easy.

Code: Select all

```
(-3)! = (-3)*(-2)*(-1) = -6
(-4)! = (-4) * (-3)! = (-4) * (-6) = 24.
```

Regards,

Suman.

I think these lines of code

make sense only to the Online Judge

Code: Select all

```
if (i<0) {
if (-i%2==0) {
printf("Underflow!\n");
continue;
} else {
printf("Overflow!\n");
continue;
}
}
```

i == - 10 -> Underflow ???

Fact (-10) should be same as Fact (10) which is a number

lying within the limits MIN = 10000 ... MAX = 6227020800

Actually if we are talking about N > 0 only ( I know we have

to deal with negative input ) then we have :

8! is the first factorial >=10 000

13! is the max limit == 6227020800

So is there any logic for the output our program should

produce for N < 0. And especially for the case :

Code: Select all

`-13 <= N <= -8 `

Like

-10 -> Underflow!

-8 -> Underflow!

-11 -> Overflow!

-13 -> Overflow!

-400 -> Underflow!

The last one is interesting. To my knowledge X = ( - 400 ) !

is a huge positive number. Or ... ?

- J&Jewel
- New poster
**Posts:**50**Joined:**Thu Jul 31, 2003 10:43 am**Location:**Daffodil University,Dhaka,Bangladesh-
**Contact:**

### i get W/A why?

#include<stdio.h>

int main()

{

long input;

//freopen("c:\\10323.txt","r",stdin);

while(scanf("%ld",&input)==1)

{

if(input>=14) printf("Overflow!\n");

else if( input>7)

{

if(input==8) printf("40320\n");

if(input==9) printf("362880\n");

if(input==10) printf("3628800\n");

if(input==11) printf("39916800\n");

if(input==12) printf("479001600\n");

if(input ==13) printf("6227020800\n");

}

else if(input<=7 && input>=0) printf("Underflow!\n");

else if(input <=-14 && (-1*input)%2==0) printf("Overflow!\n");

else if(input <=-14 && (-1*input)%2!=0) printf("Underflow!\n");

else if(input > -14 && input <= -8 && (-1*input)%2==0)

{

if(input==-8) printf("40320\n");

if(input==-10) printf("3628800\n");

if(input==-12) printf("479001600\n");

}

else printf("Underflow!\n");

}

return 0;

}

[/code]

int main()

{

long input;

//freopen("c:\\10323.txt","r",stdin);

while(scanf("%ld",&input)==1)

{

if(input>=14) printf("Overflow!\n");

else if( input>7)

{

if(input==8) printf("40320\n");

if(input==9) printf("362880\n");

if(input==10) printf("3628800\n");

if(input==11) printf("39916800\n");

if(input==12) printf("479001600\n");

if(input ==13) printf("6227020800\n");

}

else if(input<=7 && input>=0) printf("Underflow!\n");

else if(input <=-14 && (-1*input)%2==0) printf("Overflow!\n");

else if(input <=-14 && (-1*input)%2!=0) printf("Underflow!\n");

else if(input > -14 && input <= -8 && (-1*input)%2==0)

{

if(input==-8) printf("40320\n");

if(input==-10) printf("3628800\n");

if(input==-12) printf("479001600\n");

}

else printf("Underflow!\n");

}

return 0;

}

[/code]

I hate Wrong Answer!

### Give accepted input and output

I also get Wrong Answer.

Can anybody give some input and out put data. I could not find the reson of my wrong answer.

Can anybody give some input and out put data. I could not find the reson of my wrong answer.

### Special Case On 10323

There Are Many Post On This topic In Board Find It..

Actually There Is A Negetive Input.

For This You Need To Give A Special Case.

That Is Is Even Then Underflow

And If Odd Then Overflow.

Othecase Is Simple.

Like This

-1

-5

-4

output:

Overflow!

Overflow!

Underflow!

Rocky

Actually There Is A Negetive Input.

For This You Need To Give A Special Case.

That Is Is Even Then Underflow

And If Odd Then Overflow.

Othecase Is Simple.

Like This

-1

-5

-4

output:

Overflow!

Overflow!

Underflow!

Rocky

### Please Explain 10323

Thanks Rocky

I got the Point and get AC.

Thanks

Iftekhar

I got the Point and get AC.

Thanks

Iftekhar

### About Analysis

Actualy I Can Not Make The Full Prove Of This Problem In Case Of Negetive Input.Is Any Can Prove It Then Please Say....????

Thank's In Advance

Rocky

Thank's In Advance

Rocky

### 10323 Compiler Error

Please help me with this code.

I am using long long data structure and getting CE.

I am using long long data structure and getting CE.

Code: Select all

```
/*
Name: Factorials! You must be Kidding!
Number: 10323
Type : Factorials
Process : ON
Author :Salman Zaman
Email : zamansalman@gmail.com
Date : 02/06/05 01:27
*/
#include<stdio.h>
//#include<conio.h>
long long facto(long long a){
if(a==1){
return a;
}
else{
return facto(a-1)*a;
}
}
int main(){
long long n,temp;
// freopen("10323.txt","r",stdin);
while(scanf("%lld",&n)!=EOF){
temp=facto(n);
if(temp<10000){
printf("Underflow!\n");
}
else if(temp>6227020800){
printf("Overflow!\n");
}
else{
printf("%lld\n",temp);
}
}
// getch();
return 0;
}
```