10515 - Powers Et Al.
Moderator: Board moderators
10515 - Powers Et Al.
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]
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.
-
- Learning poster
- Posts: 54
- Joined: Sun May 18, 2003 1:19 am
- Location: Rio de Janeiro, Brazil
- Contact:
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
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
Mauricio Oliveira Carneiro
-
- New poster
- Posts: 38
- Joined: Thu Mar 27, 2003 9:12 pm
- Location: Aguascalientes, Mexico
- Contact:
Why WA!
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!
[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!
-
- Experienced poster
- Posts: 131
- Joined: Thu Apr 17, 2003 8:39 am
- Location: Baku, Azerbaijan
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!
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
NO sigNature
10515 TLE
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]
[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]
What's the error?
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:](./images/smilies/icon_evil.gif)
[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:](./images/smilies/icon_evil.gif)
God is dead - Nietzsche
Nietzsche is dead - God
Nietzsche is dead - God
-
- New poster
- Posts: 12
- Joined: Sun Jun 01, 2003 12:21 pm
- Location: Pune, India
Error No 1 :
[cpp]if(!m && !m) break;[/cpp]
You probably mean [cpp]if(!m && !n) break;[/cpp]
And I can tell you there are more.....![:-?](./images/smilies/icon_confused.gif)
I wrote close to 150 lines to solve this problem.....takes 0.070 secs.
You probably mean [cpp]if(!m && !n) break;[/cpp]
And I can tell you there are more.....
![:-?](./images/smilies/icon_confused.gif)
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.