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

jydy
New poster
Posts: 5
Joined: Sun Apr 07, 2002 2:00 am

568 - Just the Facts

Post 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.
chang
New poster
Posts: 16
Joined: Wed Jan 16, 2002 2:00 am

Post 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)
Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen »

jydy: it's the last non zero digit, not first.
so the last non zero digit of 3125! is obviously 2. :P
wenzhi cai
New poster
Posts: 9
Joined: Sat Jun 29, 2002 10:59 am
Location: china
Contact:

568pe!!!

Post by wenzhi cai »

my output code:
[cpp] printf("%5d -> %d\n",n,sum);


I got pe and can't understand why. :cry: [/cpp][/code]
tea
New poster
Posts: 2
Joined: Thu Oct 03, 2002 5:38 pm

568 Why PE?

Post 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?
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

not realize

Post by anupam »

:oops: :evil: please send eor whole program so that i can realize what u meant by the variables. :oops: :evil:
"Everything should be made simple, but not always simpler"
junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Don't worry about PE

Post 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
zdroyer
New poster
Posts: 1
Joined: Mon Dec 09, 2002 8:08 pm
Location: Poland

Re: 568 Why PE?

Post 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:
takumi
New poster
Posts: 10
Joined: Tue Dec 10, 2002 6:15 pm

568 time limit helllp

Post 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]
takumi
New poster
Posts: 10
Joined: Tue Dec 10, 2002 6:15 pm

Post 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.
Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post 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..
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »

:oops: its very easy,
just use string to calculate fac no.
and then you can easily find yor ans.
thanks.[/b]
"Everything should be made simple, but not always simpler"
takumi
New poster
Posts: 10
Joined: Tue Dec 10, 2002 6:15 pm

Post 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.
junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post 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:
takumi
New poster
Posts: 10
Joined: Tue Dec 10, 2002 6:15 pm

Post 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);
Post Reply

Return to “Volume 5 (500-599)”