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

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

Post by Ghust_omega » Mon Sep 06, 2004 6:01 pm

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

matrix2
New poster
Posts: 19
Joined: Wed Jul 21, 2004 11:14 am
Location: Suceava, Romania
Contact:

Post by matrix2 » Wed Sep 15, 2004 1:45 pm

They are really kidding (I mean the problem setter/s)
It is a good problem with a hidden idea. This problem is a discovery problem in means we must to find out a hidden idea.
Things are simple, but we make them complex.

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am

10323 Why Wrong Ans.

Post by efr_shovo » Tue Sep 28, 2004 7:06 am

/* 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]);
}
}
}

naybet
New poster
Posts: 2
Joined: Thu Feb 03, 2005 10:16 pm

10323 factorial with negative numbers

Post by naybet » Thu Feb 03, 2005 10:51 pm

i read the previous topics about this problem
are u sure i must handle negative numbers
if yes
how can i do this? :wink:

is there a factorial for negative numbers[/code]

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar » Fri Feb 04, 2005 7:56 am

Hi,

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.

naybet
New poster
Posts: 2
Joined: Thu Feb 03, 2005 10:16 pm

10323

Post by naybet » Fri Feb 04, 2005 2:18 pm

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

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Post by sumankar » Fri Feb 04, 2005 2:28 pm

Hi,

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.
Do you get it now?I'll delete this post sooner than you wouls expect so ... :)

Regards,
Suman.

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Mon Feb 28, 2005 1:24 pm

What logic is there behind these lines ?

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; 
} 
}
Why is for instance the answer for
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 
Or do we just have to guess what the Judge expects as output :) ?
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 ... ? :)

User avatar
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?

Post by J&Jewel » Tue Mar 22, 2005 9:42 am

#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]
I hate Wrong Answer!

iishaque
New poster
Posts: 5
Joined: Sun Apr 03, 2005 5:11 pm
Location: Dhaka, Bangladesh

Give accepted input and output

Post by iishaque » Fri Apr 08, 2005 5:42 pm

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

User avatar
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

Special Case On 10323

Post by Rocky » Mon Apr 11, 2005 12:06 pm

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

iishaque
New poster
Posts: 5
Joined: Sun Apr 03, 2005 5:11 pm
Location: Dhaka, Bangladesh

Please Explain 10323

Post by iishaque » Sat Apr 16, 2005 7:09 am

Thanks Rocky
I got the Point and get AC.
Thanks
Iftekhar

User avatar
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

About Analysis

Post by Rocky » Wed Apr 20, 2005 6:46 am

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

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

Post by J&Jewel » Wed Apr 27, 2005 11:46 am

HI dears,
I also want to know that.
I change my code some and i got accept.
But i can`t understand that ......please any one can help us to understand it....
I hate Wrong Answer!

Salman
New poster
Posts: 25
Joined: Thu Jun 26, 2003 9:45 am

10323 Compiler Error

Post by Salman » Sun Jul 17, 2005 12:19 pm

Please help me with this code.
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;
}

Post Reply

Return to “Volume 103 (10300-10399)”