Page 1 of 3

568 - Just the Facts

Posted: Sun Apr 07, 2002 8:31 am
by jydy
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.

Posted: Sun Apr 07, 2002 10:46 am
by chang
U should use 'long long' data type. It gives u 8 byte. And change the line :
tmp %= 100
with
tmp %= 100000 ( or, tmp%=1000000)

Posted: Sun Jul 14, 2002 12:27 am
by Subeen
jydy: it's the last non zero digit, not first.
so the last non zero digit of 3125! is obviously 2. :P

568pe!!!

Posted: Sun Jul 28, 2002 6:47 am
by wenzhi cai
my output code:
[cpp] printf("%5d -> %d\n",n,sum);


I got pe and can't understand why. :cry: [/cpp][/code]

568 Why PE?

Posted: Sat Oct 05, 2002 4:35 pm
by tea
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?

not realize

Posted: Sat Oct 05, 2002 7:13 pm
by anupam
:oops: :evil: please send eor whole program so that i can realize what u meant by the variables. :oops: :evil:

Don't worry about PE

Posted: Sun Oct 06, 2002 9:04 am
by junjieliang
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. :D

Re: 568 Why PE?

Posted: Mon Dec 09, 2002 8:11 pm
by zdroyer
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 -> :wink:

568 time limit helllp

Posted: Tue Dec 10, 2002 6:20 pm
by takumi
#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]

Posted: Fri Dec 13, 2002 8:26 pm
by takumi
can anybody tell me what is wrong with m code??
i think i pass all test cases but i still get time limit exceeded
above is my source code.

Posted: Sun Dec 15, 2002 2:18 am
by Larry

Code: Select all

while ( temp % 10 == 0 ) { 
temp /= 10; 
} 
My guess is that if it gets TLE, temp becomes 0 for some case and it hangs..

Posted: Wed Dec 18, 2002 10:55 am
by anupam
:oops: its very easy,
just use string to calculate fac no.
and then you can easily find yor ans.
thanks.[/b]

Posted: Sat Dec 21, 2002 7:36 am
by takumi
use string???
how, you mean by manipulating the array like
num 24 become... array[0] = 2, array[1] = 4.
or anything else.
thanks for reply.

Posted: Sat Dec 21, 2002 2:45 pm
by junjieliang
Just a problem: How do you terminate your program? I don't see any checks for EOF (unless it happens to be the smiley face) :lol:

Posted: Sun Dec 22, 2002 5:38 am
by takumi
thanks i got accepted just now,
but still P.E is there anything wrong with this output
printf("%5d -> %d\n", num2, temp);

or should i change it like:
printf("%d -> %d\n", num2, temp);