568 - Just the Facts
Moderator: Board moderators
568 - Just the Facts
the first non-zero digit of 3125! comes out as a 5 whereas in the sample input it's said to be 2.
the following is my code, thank you.
#include<stdio.h>
void main()
{
long int tmp=1; //temporary tens and units digit data
long int i;
long int input,result;
scanf("%d",&input);
for(i=2;i<=input;i++)
{
tmp*=i;
while(tmp%10==0)
tmp/=10;
tmp%=100; //I think here is where the problem resides
}
result=tmp%10;
printf("%d",result);
}
in each loop I save only two digits counting from the first non-zero digit.
the following is my code, thank you.
#include<stdio.h>
void main()
{
long int tmp=1; //temporary tens and units digit data
long int i;
long int input,result;
scanf("%d",&input);
for(i=2;i<=input;i++)
{
tmp*=i;
while(tmp%10==0)
tmp/=10;
tmp%=100; //I think here is where the problem resides
}
result=tmp%10;
printf("%d",result);
}
in each loop I save only two digits counting from the first non-zero digit.
-
- New poster
- Posts: 9
- Joined: Sat Jun 29, 2002 10:59 am
- Location: china
- Contact:
568pe!!!
my output code:
[cpp] printf("%5d -> %d\n",n,sum);
I got pe and can't understand why. [/cpp][/code]
[cpp] printf("%5d -> %d\n",n,sum);
I got pe and can't understand why. [/cpp][/code]
568 Why PE?
i use:
printf("%5d -> %d\n",input_value,last_digit);
to do the output.
why i have PE in this question?
any problem with that?
printf("%5d -> %d\n",input_value,last_digit);
to do the output.
why i have PE in this question?
any problem with that?
not realize
please send eor whole program so that i can realize what u meant by the variables.
"Everything should be made simple, but not always simpler"
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore
Don't worry about PE
Usually if your program gets accepted, and you don't see any reason why it gets PE, then forget about it. There are many problem which has over 90% of people getting PE, and virtually no one knows why. As long as it's AC it means your program is correct, so don't worry.
Re: 568 Why PE?
tea wrote:i use:
printf("%5d -> %d\n",input_value,last_digit);
to do the output.
why i have PE in this question?
any problem with that?
try
printf("%d -> %d\n",input_value,last_digit);
%d -> not %5d ->
568 time limit helllp
#include <stdio.h>
int main()
{
int num, num2, i, temp = 1, j;
for (;;) {
scanf("%d", &num);
num2 = num;
temp = 1;
for ( i = 2; i <= num; i++ ) {
temp = temp * i;
while ( temp % 10 == 0 ) {
temp /= 10;
}
temp %= 100000;
}
temp %= 10;
printf("%5d -> %d\n", num2, temp);
}
return 0;
}[c][/c]
int main()
{
int num, num2, i, temp = 1, j;
for (;;) {
scanf("%d", &num);
num2 = num;
temp = 1;
for ( i = 2; i <= num; i++ ) {
temp = temp * i;
while ( temp % 10 == 0 ) {
temp /= 10;
}
temp %= 100000;
}
temp %= 10;
printf("%5d -> %d\n", num2, temp);
}
return 0;
}[c][/c]
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
Code: Select all
while ( temp % 10 == 0 ) {
temp /= 10;
}
-
- Experienced poster
- Posts: 169
- Joined: Wed Oct 31, 2001 2:00 am
- Location: Singapore