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

zhangl
New poster
Posts: 4
Joined: Tue Nov 05, 2002 2:28 am
Location: China

Post by zhangl »

why die i got wrong?
who can help me?
Although being far far away,
Still I do do feel you.
Through the sky,
Across the ocean,
I hear

turingcomplete
New poster
Posts: 11
Joined: Wed Oct 09, 2002 7:31 pm
Contact:

Post by turingcomplete »

To the problem setter: thanks for wasting an hour of time. If you want to make up some function then don't call it factorial, as it's really confusing to those of us who know that factorial is only defined for 0+.

:x

Ghost77 dimen
Learning poster
Posts: 67
Joined: Sun Sep 22, 2002 5:40 am
Location: Taiwan

Post by Ghost77 dimen »

Come on, turingcomplete. 8)

The title is so clear that it play a trick on us.

Didn't you think for a while why it said that " You must be kidding."?

8)

ec3_limz
Learning poster
Posts: 79
Joined: Thu May 23, 2002 3:30 pm
Location: Singapore

10323

Post by ec3_limz »

Why WA? :roll:

[cpp]#include <iostream.h>
typedef unsigned long long ULLT;

int main() {
const ULLT UNDER = 10000LL, OVER = 6227020800LL;
ULLT limit, fact, i;

while (cin >> limit) {
fact = 1;
for (i = 1; i <= limit; i++) {
fact *= i;
if (fact > OVER) {
cout << "Overflow!\n";
break;
}
}

if (fact <= OVER) {
if (fact < UNDER)
cout << "Underflow!\n";
else
cout << fact << '\n';
}
}

return 0;
}[/cpp]

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

The problem doesn't state the minimum input, so you must handle negative factorial, like : -1!, -2!, -3!, ...
To find the answer of that problem, just simulate this formula :
(n-1) ! = n ! / n

Good Luck ! :D

knightmare
New poster
Posts: 4
Joined: Sat Nov 23, 2002 2:00 pm

Post by knightmare »

For negative numbers it's always underflow or overflow (depends on whether the number is even or odd).

This problem is completely stupid (mathematically incorrect), as you can read on this thread:

http://acm.uva.es/board/viewtopic.php?t=803

You can start flaming me for posting the "solution" here, I don't care... People shouldn't be supposed to guess, only to think about logical things.

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

P 10323

Post by Red Scorpion »

How if the input is :
Input :
-1
-2
-3

Ouput:
Overflow
Underflow
Overflow

Is This Right ?
Regards,
RED SCORPION :lol:

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion »

Yes, I Got AC,
when it is a negative number, I look if it is EVEN,
then the output should be Underflow!, else if
it is ODD then the output should be Overflow!

Thanks,
RED SCORPION :lol:

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

Post by angga888 »

Yes, you're right, Red Scorpion. :D
And that pattern will repeat again and again (for negative factorial).
However, I still think that negative factorial is undefined. :wink:

razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Location: SUST,BANGLADESH
Contact:

Give some explanation

Post by razibcse »

I can't understand how to calculate factorial of negative numbers...if u put n=0 in the formula (n-1)!=n!/n, u get
-1!=0!/0...how is this possible?

pls give some explanation of the process how negative even numbers get Underflow! and odd numbers get Overflow!...


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Razib
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Our lives improve only when we take chances - and the first and most
difficult risk we can take is to be honest with ourselves.[/quote]

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Location: BANGLADESH
Contact:

Post by Jalal »

Yes! no doubt about it!
One of the most stupid problem it is!
As far i know acm is for updating our brain.
Not for damage our topic's with bad theory
just to make a problem ubsolved :x

VitorRodrigues
New poster
Posts: 9
Joined: Wed Apr 16, 2003 6:50 pm
Location: Braga, Portugal
Contact:

Post by VitorRodrigues »

Hisoka and razibcse, you do not have to use any formula to calculate factorial of negative numbers. Jus print "Overflow!" if the number is odd, or "Underflow!" if the number is even.

Good luc :)

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

Post by Eric »

I get WA.
I think the problem is :
  • It used to contain the correct algorithm, but I deleted.
Can anyone help me?
Last edited by Eric on Thu Apr 17, 2003 12:42 pm, edited 1 time in total.

little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

Eric: You do Pascal, don't you? PM me your code, and I'll have a look.

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

Post by Eric »

I get Accepted now. Thanks Joey.
It is really a careless mistake.

Post Reply

Return to “Volume 103 (10300-10399)”