Page 1 of 9

10515 - Powers Et Al.

Posted: Sun Jun 15, 2003 7:15 am
by Eric
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]

Posted: Sun Jun 15, 2003 8:01 am
by lowai
i got WA with my Pascal code.
and i could get AC by using scanf("%s%s") in C...

Posted: Sun Jun 15, 2003 10:20 am
by carneiro
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

Posted: Sun Jun 15, 2003 12:49 pm
by lowai
0
1
4
2
7
9
4
5
6
1
4
6
1
1
9
6

Posted: Sun Jun 15, 2003 4:03 pm
by Noim
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++.

Posted: Sun Jun 15, 2003 5:15 pm
by Eric
But somebody can get AC with Pascal.
What's the problem of my program?

Posted: Sun Jun 15, 2003 7:06 pm
by carneiro
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 !

Why WA!

Posted: Tue Jun 17, 2003 11:00 pm
by Pier
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!

Posted: Wed Jun 18, 2003 1:08 am
by carneiro
Have you tried the input I posted here?

Posted: Wed Jun 18, 2003 4:22 pm
by Farid Ahmadov
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!

10515 TLE

Posted: Mon Jun 23, 2003 3:28 pm
by r.z.
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]

Posted: Mon Jun 23, 2003 4:40 pm
by Overlord
Eric try this:

100 100
0 100
0 0

What's the error?

Posted: Mon Jun 23, 2003 5:07 pm
by Overlord
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:

Posted: Mon Jun 23, 2003 5:31 pm
by Eric
Thanks, Overlord. I've got accepted.

Error No 1 :

Posted: Tue Jun 24, 2003 2:40 am
by technogeek
[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.