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

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

13! = 6227020800, which exceeds integer limit.
Ami ekhono shopno dekhi...
HomePage
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

CE....

Post by Obaida »

Some one please help me I am getting CE.....

Code: Select all

#include<stdio.h>
int main()
{
	long double fact,i,n,count;
	while(scanf("%Lf",&n)==1)
	{
		fact=1;
		count=1;
		for(i=1;i<=n;i++)
		{
			fact=fact*i;
			if(fact>6227020800)
			{
				count=0;
				printf("Overflow!\n");
				break;
			}
		}
		if(count!=0)
		{
			if((fact/1000)<1)
			{
				printf("Underflow!\n");
			}
			else
			{
				printf("%.0Lf\n",fact);
			}
		}
	}
	return 0;
}
try_try_try_try_&&&_try@try.com
This may be the address of success.
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

Obaida, I submitted your code, and got Wrong answer. Did you select proper language option before submit?
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

WA.....

Post by Obaida »

some one please help me still I got WA....
Last edited by Obaida on Sat Mar 01, 2008 12:54 pm, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

So did you get accepted?
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Still WA...

Post by Obaida »

But still........I got WA... Hear is my code........

Code: Select all

Code removed
}
Last edited by Obaida on Sun Mar 02, 2008 5:35 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

try this input

Code: Select all

7
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Oh....no..

Post by Obaida »

Code: Select all

Actually I mistake to read the problem......HA....Ha...Ha...
try_try_try_try_&&&_try@try.com
This may be the address of success.
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Re: Oh....no..

Post by emotional blind »

Obaida wrote:

Code: Select all

Actually I mistake to read the problem......HA....Ha...Ha...
Are you happy with that? or proud? :o
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Ok

Post by Obaida »

My smile doesn't meen my happyness or my proud... It means How much I had to be careful.
try_try_try_try_&&&_try@try.com
This may be the address of success.
emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

Be Careful, Be Happy :)
chenaren
New poster
Posts: 1
Joined: Sun Nov 30, 2008 6:39 am

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

Post by chenaren »

1/0 is not defined rather than infinite

the problem may have bad influence on the mathematical concept of the solver

:-?
sefakilic
New poster
Posts: 7
Joined: Wed Mar 11, 2009 8:12 pm

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

Post by sefakilic »

I've read all posts in this topic.

I believe that I am doing right, but unfortunately I don't. I am getting WA.

Here is my code:

Code: Select all

#include "stdio.h"

unsigned long iter_factorial(int n) {
    unsigned long accu = 1;
    unsigned long i;
    for(i = 1; i <= n; i++) {
        accu *= i;
    }
    return accu;
}

int main() {
	
	unsigned long x;
	int a;
	while( scanf("%d", &a) != EOF )
	{
		if( a <= 7 && a >= 0)
			printf("Underflow!\n");
		else if(a > 13)
			printf("Overflow!\n");
		else if(a < 0)
		{
			if( a / 2 * 2 == a)
				printf("Underflow!\n");
			else 
				printf("Overflow!\n");
		}
		else {
			x = iter_factorial(a);
			printf("%lu\n",x);
		}
	}
	
	return 0;
}

Thank you..
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

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

Post by Obaida »

I didn't checked your code. But i think you should use long long. :)
try_try_try_try_&&&_try@try.com
This may be the address of success.
sefakilic
New poster
Posts: 7
Joined: Wed Mar 11, 2009 8:12 pm

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

Post by sefakilic »

My factorial function calculates the factorials of numbers between 8 and 13 [including them]. But I was getting WA.

I replaced the factorial function with the precalculated values. ( if (x == 8 ) printf("...") .....)

And I got AC.
Post Reply

Return to “Volume 103 (10300-10399)”