568 - Just the Facts
Moderator: Board moderators
-- 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
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-- 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
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
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]
[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]
I got PE as well...
I'm quite sure that the judge is wrong on this issue (Look at the statistics!)![:P](./images/smilies/icon_razz.gif)
I'm quite sure that the judge is wrong on this issue (Look at the statistics!)
![:P](./images/smilies/icon_razz.gif)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- 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?![:D](./images/smilies/icon_biggrin.gif)
I hope this helps someone!![:roll:](./images/smilies/icon_rolleyes.gif)
Since you only want the final digit, why bother with the rest of them?
![:D](./images/smilies/icon_biggrin.gif)
I hope this helps someone!
![:roll:](./images/smilies/icon_rolleyes.gif)
Daniel
UFRN HDD-1
Brasil
UFRN HDD-1
Brasil
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
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
It's impossible!
I got AC with same loop
take a look
Strange?!
I got AC with same loop
take a look
Code: Select all
while(scanf("%d",&n)==1)
{
printf("%5d -> %d\n",n,proc(n));
}
keep it real!
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 ???
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 ...
Code: Select all
ACC NOW :D, code removed...
Thanks in advance ...
Last edited by nymo on Wed Oct 26, 2005 7:43 pm, edited 1 time in total.
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![:D](./images/smilies/icon_biggrin.gif)
![:(](./images/smilies/icon_frown.gif)
EDIT: ACC now
![:D](./images/smilies/icon_biggrin.gif)
-
- 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;
}
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;
}
-
- 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.
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.
Have you checked your sample input and output.
Code: Select all
sum=1;
for(i=n;i>0;i--)
{
sum*=i;
}
Thanks
MAP.