高精度代码
加法
procedure add(a,b,c:arr);
var i,x,len:longint;
begin
len:=max(a[0],b[0]);x:=0;
for i:=1 to len+1 do
begin
c[i]:=a[i]+b[i]+x;
x:=c[i] div 10;
c[i]:=c[i] mod 10;
end;
if c[len+1]>0 then len:=len+1;
end;
减法
procedure minu(var a,b,c:arr);
var i:longint;
begin
fillchar(c,sizeof(c),0);
for i:=1 to a[0] do
begin
if a[i]<b[i] then
begin
a[i]:=a[i]+10; a[i+1]:=a[i+1]-1;
end;
c[i]:=a[i]-b[i];
end;
c[0]:=a[0];
while (c[c[0]]=0)and(c[0]>1) do dec(c[0]);
end;
procedure mul(var a,b,d:arr);
var i,j,x:longint;
begin
fillchar(v,sizeof(v),0);
for i:=1 to a[0] do
begin x:=0;
for j:=1 to b[0] do
begin
v[i+j-1]:=a[i]*b[j]+x+v[i+j-1];
x:=v[i+j-1] div 10;
v[i+j-1]:=v[i+j-1] mod 10;
end;
v[i+j]:=x;
end;
v[0]:=a[0]+b[0];
while (v[v[0]]=0)and(v[0]>1) do dec(v[0]);
d:=v;
end;
除法
function compare(var a,b:arr):boolean;
var i:longint;
begin
if a[0]>b[0] then exit(true) else if a[0]<b[0] then exit(false);
if a[0]=b[0] then
begin
for i:=a[0] downto 1 do
if a[i]>b[i] then exit(true) else if a[i]<b[i] then exit(false);
end;
end;
procedure worked(var a,b,c:arr);
var
i,j,x:longint;
begin
x:=0;
fillchar(c,sizeof(c),0);
fillchar(d,sizeof(d),0);
d[1]:=0; d[0]:=1;
w[1]:=0; w[2]:=1; w[0]:=2;
for i:=a[0] downto 1 do
begin
mul(d,w,d);
d[1]:=a[i];
while compare(d,b)=true do
begin
minu(d,b,d);
inc(c[i]);
end;
end;
c[0]:=a[0];
while (c[c[0]]=0)and(c[0]>1) do dec(c[0]);
end;