568 - Just the Facts

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam » Sun Dec 22, 2002 1:36 pm

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
Location: BANGLADESH
Contact:

Post by Jalal » Sun Jan 05, 2003 12:05 am

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.
:wink:

User avatar
ridwan
New poster
Posts: 2
Joined: Thu Apr 03, 2003 4:44 am
Location: bangladesh
Contact:

Post by ridwan » Wed Apr 09, 2003 7:33 am

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 by Observer » Fri Jul 11, 2003 9:45 am

-- 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 by Observer » Fri Jul 11, 2003 10:21 am

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

Post by Rene » Sat Jul 12, 2003 1:47 pm

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

Post by Observer » Mon Jul 21, 2003 2:42 pm

I got PE as well...

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

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

Post by danielrocha » Tue Dec 16, 2003 1:04 pm

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

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

jackie
New poster
Posts: 47
Joined: Tue May 04, 2004 4:24 am

Post by jackie » Thu Aug 05, 2004 9:36 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

User avatar
jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

Post by jaracz » Fri Jun 17, 2005 8:24 pm

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

Post by nymo » Mon Oct 03, 2005 5:59 pm

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 ?

Thanks in advance ...
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 !!!

Post by nymo » Sun Oct 09, 2005 1:25 pm

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 :D

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

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

Post by athlon19831 » Wed Jan 25, 2006 5:31 pm

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
Location: Bangladesh
Contact:

Post by mamun » Wed Jan 25, 2006 5:58 pm

Use an array to precalculate values upto 10000.

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

Post by mohiul alam prince » Tue Jan 31, 2006 6:34 am

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.

Post Reply

Return to “Volume 5 (500-599)”