讨论 / 终于AC 高精度有小错查处出
beana 2010-10-26 21:34:00
点我顶贴 收藏 删除
爽了

type

cao=array[1..100] of integer;

var

m:string;

t,i,n,gex:integer;

a:cao;

function yes(x:cao):boolean;

var

l,r,i:integer;

begin

l:=1;

yes:=true;

r:=gex;

repeat

if x[l]<>x[r] then exit(false);

inc(l);

dec(r);

until l>=r;

end;

function get(x:char):integer;

begin

case x of

'0'..'9':get:=ord(x)-ord('0');

'a'..'f':get:=10+ord(x)-ord('a');

'A'..'F':get:=10+ord(x)-ord('A');

end;

end;

procedure add(var a:cao);

var

b:cao;

i,x,y,temp:integer;

begin

fillchar(b,sizeof(b),0);

x:=gex;

for i:=1 to x do

b[x-i+1]:=a[i];

temp:=0;

for i:=1 to (1+x) do

begin

y:=a[i]+b[i]+temp;

a[i]:=(y) mod n;

temp:=(y) div n;

end;

if not(a[1+x]=0) then inc(gex);

end;

begin

readln(n);

readln(m);

fillchar(a,sizeof(a),0);

for i:=1 to length(m) do

a[length(m)-i+1]:=get(m[i]);

for i:=100 downto 1 do

if a[i]<>0 then

begin

gex:=i;

break;

end;

t:=0;

for i:=1 to 30 do

begin

if yes(a) then break;

add(a);

inc(t);

end;

if yes(a) then write(t)

else write('Impossible');

end.

查看更多回复
提交回复