Page 5 of 8

Posted: Sun Jul 17, 2005 2:32 pm
by mf
//-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".

Posted: Mon Jul 25, 2005 3:59 am
by Salmin Sultana
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

10323 factorial u must kidding

Posted: Thu Jul 20, 2006 2:32 pm
by ayeshapakhi
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.

Posted: Thu Jul 20, 2006 3:11 pm
by jan_holmes
I think the problem of your code is this part :

Code: Select all

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

10323 WA >>>>NEED HELP

Posted: Sun Jul 23, 2006 2:40 pm
by sv90
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;
}

Posted: Sun Jul 23, 2006 3:51 pm
by mf
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.

10323 txt file missing

Posted: Sat Nov 11, 2006 6:55 pm
by anik
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!!

Posted: Sat Nov 11, 2006 9:48 pm
by Jan
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.

Posted: Wed Nov 15, 2006 5:47 pm
by anik
but i am still getting same error!!

Posted: Wed Nov 15, 2006 6:00 pm
by Jan
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.

Posted: Thu Nov 16, 2006 5:13 pm
by Observer
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.

Posted: Wed Mar 28, 2007 2:28 pm
by jainal cse du
Why judge response WA,
I need help

Code: Select all

Code removed after AC.

Posted: Wed Mar 28, 2007 5:04 pm
by abdullah<cse du>
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?

Please explaine it.

ABDULLAH

Posted: Thu Mar 29, 2007 7:10 am
by helloneo
abdullah<cse du> wrote:

Code: Select all

#define N 6227020800LL 
Why LL?

Please explaine it.

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

but why this is WA

Posted: Tue Jun 19, 2007 9:20 am
by bishop
plz help for WA

Code: Select all


Code removed


:)
thanks