## 568 - Just the Facts

Moderator: Board moderators

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:
whenever printing you should consider the last line specially.
there may be a \n after last input, may not. it's main cause of pe
thanks.
"Everything should be made simple, but not always simpler"

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Contact:
I think there is a little tric with the prob.
if anyone just findout the number of power of two and
five and deduct them till that number from 2
and do mod in every section that make the solve faster.

ridwan
New poster
Posts: 2
Joined: Thu Apr 03, 2003 4:44 am
Contact:
i think you should divide with 10000 instead of 10

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
-- Post removed by Observer --
Last edited by Observer on Wed Oct 12, 2005 12:55 pm, edited 2 times in total.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
-- Post removed by Observer --
Last edited by Observer on Wed Oct 12, 2005 12:55 pm, edited 1 time in total.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

Rene
New poster
Posts: 13
Joined: Mon May 05, 2003 4:40 am
Location: Shanghai,China

### 568 Why PE?

why my answer always gets PE?
[cpp]
#include <iostream.h>
#include <stdio.h>

int main()
{
long n,i,b;
while (cin >> n)
{
b = 1;
for (i = 1;i <= n;i++)
{
b *= i;
while (!(b % 10))
b /= 10;
b %= 100000;
}
while (!(b % 10))
b /= 10;
b %= 10;
printf ("%5ld -> %ld\n",n,b);
}
return 0;
}[/cpp]

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
I got PE as well...

I'm quite sure that the judge is wrong on this issue (Look at the statistics!)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

danielrocha
New poster
Posts: 44
Joined: Sun Apr 27, 2003 3:17 am
Location: Rio Grande do Norte - Brazil
Contact:

### You don't need to calculate the entire number!

Just to remind you guys that are trying to solve this problem: you don't need to calculate the entire number! It would be so big that it would not fit into any data type, and you don't need to implement "string array" or a "big int" class..

Since you only want the final digit, why bother with the rest of them?

I hope this helps someone!
Daniel
UFRN HDD-1
Brasil

jackie
New poster
Posts: 47
Joined: Tue May 04, 2004 4:24 am
Just factor 2 and factor 5 make 0s in the result and obviously factor 2 is more than factor 5 in the factorial.
Think about the last digits which don't contain 2 or 5s then add num(2) - num(5) 2s to the result and get the answer.

num(n) how many factor ns in the factorial.

hope it can help

good luck

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland
It's impossible!
I got AC with same loop
take a look

Code: Select all

``````while(scanf("%d",&n)==1)
{
printf("%5d -> %d\n",n,proc(n));
}``````
Strange?!
keep it real!

nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

### Keep getting WA !!!

Hi, i am getting WA in this problem, i tried several inputs and it seems okay, I tried to precalculate the last digit, what is wrong with my code ???

Code: Select all

``````ACC NOW :D, code removed...
``````
I submitted it several times with different modification and every time its WA. Can anyone help me to find me my bug or with some i/o for which this code fails ?

Last edited by nymo on Wed Oct 26, 2005 7:43 pm, edited 1 time in total.

nymo
Experienced poster
Posts: 149
Joined: Sun Jun 01, 2003 8:58 am
Location: :)

### I need help on this !!!

I 've tried several ways and it is still WA. Any critical I/O for which my above program fails will be a great help. Can you help me to find me my bugs (coz i 've failed to find )??? Thanks anyway.

EDIT: ACC now

athlon19831
New poster
Posts: 20
Joined: Thu Jan 19, 2006 2:32 pm

### 568 how to reduce the run time? anyone can help me ?

i found the run time is too long.
this is my code:
#include "iostream.h"
#include "stdio.h"

int main(int argc, char* argv[])
{
long n;
long sum;
long i;
while(cin>>n)
{
sum=1;
for(i=n;i>0;i--)
{
sum*=i;
}
while(sum>0)
{
if(sum%10!=0)
{
cout<<sum%10<<endl;
sum/=10;
break;
}
else
sum/=10;
}
}
return 0;
}

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Contact:
Use an array to precalculate values upto 10000.

mohiul alam prince
Experienced poster
Posts: 120
Joined: Sat Nov 01, 2003 6:16 am
Location: Dhaka (EWU)
Hi athlon19831

Have you checked your sample input and output.

Code: Select all

``````sum=1;
for(i=n;i>0;i--)
{
sum*=i;
}
``````
your this part is totally wrong. (when you multiply the value at that time it exceed the integer range) Try to solve this problem in another approch.

Thanks
MAP.