- 回文数
- 2017-07-07 21:45:34 @
var
x,y,n,i,j,bs:longint;
s,m:string;
a:array[1..100] of longint;
function hws(e:longint):boolean;
var
bj,i:longint;
begin
bj:=0;
for i:=1 to e do
if a[i]<>a[e-i+1]
then bj:=1;
if bj=0
then hws:=true
else hws:=false;
end;
begin
readln(n); readln(m);
x:=length(m);
for i:=x downto 1 do
case m[i] of
'0'..'9':a[x-i+1]:=ord(m[i])-48;
'A'..'F':a[x-i+1]:=ord(m[i])-55;
end;
bs:=0;
while not hws(x) do
begin
for i:=1 to x do
begin
a[i]:=a[i]+a[x-i+1];
a[i+1]:=a[i+1]+(a[i] div n);
a[i]:=a[i] mod n;
end;
if a[x+1]<>0
then inc(x);
inc(bs);
if bs>30
then break;
end;
if bs<=30
then writeln('STEP=',bs)
else writeln('Impossible');
end.
1 条评论
-
Empty City LV 7 @ 2017-07-08 10:55:56
嗯~~~~~~~~~
- 1