10515 - Powers Et Al.

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

Moderator: Board moderators

Post Reply
Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

10515 - Powers Et Al.

Post by Eric » Sun Jun 15, 2003 7:15 am

Isn't it just calculate the last digit of M and last two digit of N and find the last sigit of the answer?
But I get Wrong Answer. Can anyone help me?
[pascal]Code is deleted[/pascal]
Last edited by Eric on Mon Jun 23, 2003 5:30 pm, edited 1 time in total.

lowai
New poster
Posts: 48
Joined: Mon Apr 29, 2002 1:26 pm

Post by lowai » Sun Jun 15, 2003 8:01 am

i got WA with my Pascal code.
and i could get AC by using scanf("%s%s") in C...

carneiro
Learning poster
Posts: 54
Joined: Sun May 18, 2003 1:19 am
Location: Rio de Janeiro, Brazil
Contact:

Post by carneiro » Sun Jun 15, 2003 10:20 am

Iowai, what's the output of your accepted solution to this input :


0 238479283749827394234
1 2340982309420394802
2 2
2 5
3 3
3 74
4 982374982739487239847298374982374982734987
5 23849823498
6 2342
7 444444
8 3999949230402394
8 24
9 2345996959645456
2 0
209384032409803948209 4032094809238409238409
8932749872394729346628364 234972983749823749872394789234
0 0
[]s
Mauricio Oliveira Carneiro

lowai
New poster
Posts: 48
Joined: Mon Apr 29, 2002 1:26 pm

Post by lowai » Sun Jun 15, 2003 12:49 pm

0
1
4
2
7
9
4
5
6
1
4
6
1
1
9
6

Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am
Location: Bangladesh

Post by Noim » Sun Jun 15, 2003 4:03 pm

hi lowai,

your words:
i got WA with my Pascal code.
and i could get AC by using scanf("%s%s") in C...
But i got AC usning scanf("%s %s") in C++.
__nOi.m....

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

Post by Eric » Sun Jun 15, 2003 5:15 pm

But somebody can get AC with Pascal.
What's the problem of my program?

carneiro
Learning poster
Posts: 54
Joined: Sun May 18, 2003 1:19 am
Location: Rio de Janeiro, Brazil
Contact:

Post by carneiro » Sun Jun 15, 2003 7:06 pm

Accepted, thank you IOWAI, I was just messing up with my bignum library, I didn't notice that I wrote the digits backward in the vector. *(

but that's ok ... I've fixed that and got accepted. Nice problem. Thanks Shahriar Manzoor !
[]s
Mauricio Oliveira Carneiro

User avatar
Pier
New poster
Posts: 38
Joined: Thu Mar 27, 2003 9:12 pm
Location: Aguascalientes, Mexico
Contact:

Why WA!

Post by Pier » Tue Jun 17, 2003 11:00 pm

Why WA!

[pascal]
Const
modu: array [0..9] of longint = (1,1,4,4,2,1,1,4,4,2);
re: array [0..9,1..4] of byte =
((0,0,0,0), (1,0,0,0), (2,4,8,6), (3,9,7,1), (4,6,0,0),
(5,0,0,0), (6,0,0,0), (7,9,3,1), (8,4,2,6), (9,1,0,0));

Var
d,n,m: byte;

Procedure lee;
var
ch,cha: char;
begin
ch:= '0';
Repeat
cha:= ch;
read(input,ch);
until (ch=' ');
d:= ord(cha)-48;
ch:= '0';
Repeat
cha:= ch;
read(input,ch);
until (eoln(input));
n:= ord(ch)-48 + (ord(cha)-48 )*10;
end;

Begin
lee;
While (d<>0) or (n<>0) do
begin
m:= n mod modu[d];
if m=0 then m:= modu[d];
if n<>0 then writeln(output,re[d,m])
else writeln(output,1);
lee;
end;
End.
[/pascal]

Any help appreciated!
There are 10 kind of people on this world: those who understand binary and those who don't!

carneiro
Learning poster
Posts: 54
Joined: Sun May 18, 2003 1:19 am
Location: Rio de Janeiro, Brazil
Contact:

Post by carneiro » Wed Jun 18, 2003 1:08 am

Have you tried the input I posted here?
[]s
Mauricio Oliveira Carneiro

Farid Ahmadov
Experienced poster
Posts: 131
Joined: Thu Apr 17, 2003 8:39 am
Location: Baku, Azerbaijan

Post by Farid Ahmadov » Wed Jun 18, 2003 4:22 pm

Hello.
Pier. Your program reads the last digit of the first number and the last two af the second.
This is correct.
But your program will terminate with input (for example) :
556666496840 54655555555554600

So you have to get the lengths of digits too.
And I think there can be spaces before and after both digits. I think your program does not support it.

Good luck!
_____________
NO sigNature

r.z.
Learning poster
Posts: 56
Joined: Thu Jun 05, 2003 1:57 pm

10515 TLE

Post by r.z. » Mon Jun 23, 2003 3:28 pm

I don't know what makes my program redundant?

[c]
#include<stdio.h>

void main()
{ double m,n,i,temp;
int digit;
do{
scanf("%lf %lf",&m,&n);
digit=1;
if(!m && !m) break;
for(i=0;i<n;i++)
{ temp=(int)m%10;
digit*=(int)temp;
digit=digit%10;
}
printf("%d\n",digit);
}while(1);
}
[/c]

Overlord
New poster
Posts: 4
Joined: Sun Jun 15, 2003 11:19 am

Post by Overlord » Mon Jun 23, 2003 4:40 pm

Eric try this:

100 100
0 100
0 0
God is dead - Nietzsche
Nietzsche is dead - God

Overlord
New poster
Posts: 4
Joined: Sun Jun 15, 2003 11:19 am

What's the error?

Post by Overlord » Mon Jun 23, 2003 5:07 pm

I've been trying to solve this problem and i always get WA. I even tried to treat cases such spaces in the beginning and in the end of the lines, or numbers "0000000" or "000055543543", but still WA. Here is my code:

[pascal]
type bignr=
record
len:byte;
v:array[0..200] of byte;
end;
var n,m:bignr;
ch:char;
q,digit:integer;
function nulla(xyz:bignr):boolean;
var q:byte;
begin
for q:=1 to xyz.len do
if xyz.v[q]<>0
then
begin
nulla:=false;
exit;
end;
nulla:=true;
end;
begin
repeat
repeat
read(ch);
until ch in ['0'..'9'];
n.len:=1;
n.v[n.len]:=ord(ch)-48;
repeat
inc(n.len);
read(ch);
if ch in ['0'..'9']
then n.v[n.len]:=ord(ch)-48;
until not (ch in ['0'..'9']);
dec(n.len);
repeat
read(ch);
until ch in ['0'..'9'];
m.len:=1;
m.v[m.len]:=ord(ch)-48;
repeat
inc(m.len);
read(ch);
if ch in ['0'..'9']
then m.v[m.len]:=ord(ch)-48;
until not (ch in ['0'..'9']);
dec(m.len);
if
((m.len>1) or
(m.len=1) and
(m.v[1]<>0)) or

((n.len>1) or
(n.len=1) and
(n.v[1]<>0))
then
begin
if nulla(n) and nulla(m)
then digit:=0
else
begin
m.v[0]:=0;
if (n.v[n.len]=0)
then if nulla(m)
then digit:=1
else digit:=0
else
begin
digit:=1;
for q:=1 to m.v[m.len-1]*10+m.v[m.len]
do digit:=(digit*n.v[n.len]) mod 10;
end;
end;
writeln(digit);
end;
until (n.len=1) and (n.v[1]=0) and
(m.len=1) and (m.v[1]=0);
end.
[/pascal]

I desperately need help :evil:
God is dead - Nietzsche
Nietzsche is dead - God

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong

Post by Eric » Mon Jun 23, 2003 5:31 pm

Thanks, Overlord. I've got accepted.

technogeek
New poster
Posts: 12
Joined: Sun Jun 01, 2003 12:21 pm
Location: Pune, India

Error No 1 :

Post by technogeek » Tue Jun 24, 2003 2:40 am

[cpp]if(!m && !m) break;[/cpp]

You probably mean [cpp]if(!m && !n) break;[/cpp]

And I can tell you there are more..... :-?
I wrote close to 150 lines to solve this problem.....takes 0.070 secs.
I wanted to change the world, but they didn't give me the source code.

Post Reply

Return to “Volume 105 (10500-10599)”