高精度乘法 pascal

来源:百度知道 编辑:UC知道 时间:2024/05/08 12:00:27
高精度乘法
输入两个正整数m、n,输出他们的积。
第一行只有一个正整数:m
第二行只有一个正整数:n
( 1 <= m,n <= 10^1000 )

那位高手帮帮我,注意:1000位啊!

program HighPrecision4_Multiply2;
const
maxlen=2000; { max length of the number }
type
hp=record
len:integer; { length of the number }
s:array[1..maxlen] of integer
{ s[1] is the lowest position
s[len] is the highest position }
end;
var
x:array[1..2] of hp;
y:hp; { x:input ; y:output }

procedure PrintHP(const p:hp);
var i:integer;
begin
for i:=p.len downto 1 do write(p.s[i]);
end;

procedure Multiply(a,b:hp;var c:hp); { c:=a+b }
var i,j,len:integer;
begin
fillchar(c,sizeof(c),0);
for i:=1 to a.len do
for j:=1 to b.len do
begin
inc(c.s[i+j-1],a.s[i]*b.s[j]);
inc(c.s[i+j],c.s[i+j-1] div 10);
c.s[i+j-1]:=c.s[i+j-1] mod 10;
end;
len:=a.len+b.len+1;
{
the product of a number with i digits and a number with j digits
can only have at most i+j+1 digits
}
while(len>1)and(c.s[le