高精度乘法和加法
结果是2^64-1
program jj;
var la,lb,lc,x,i,j :longint;
a,b,c :array [1..1000] of longint;
n,m :string;
begin
str(maxlongint,n);str(maxlongint,m)
la := length(n); lb := length(m);
for i := 1 to la do a[la-i+1] := ord(n[i])-48;
for i := 1 to lb do b[lb-i+1] := ord(m[i])-48;
for i := 1 to la do
begin
x :=0;
for j := 1 to lb do
begin
x := a[i]*b[j]+x div 10+c[i+j-1];
c[i+j-1] := x mod 10;
end;
c[i+j] := x div 10;
end;
lc := i+j;
while (c[lc]=0) and (lc>1) do lc := lc-1;
for i := lc downto 2 do
write(c[i]);
writeln(5);
end.
再问: 同志,我是个新手,别太复杂,OK?
再答: 你用的是free pascal吗?如果是,我再回答你