主题:help!
孤兰秋珊
[专家分:20] 发布于 2007-07-31 19:39:00
用高精度计算m的n次方
回复列表 (共3个回复)
沙发
Matodied [专家分:7560] 发布于 2007-07-31 22:06:00
TYPE arr = ARRAY[1..1023] OF INTEGER;
FUNCTION gjdmult(x, y: STRING): STRING;
VAR
a, b, s: arr;
l, lx, ly, d, i, j, k, v: INTEGER; z, zz: STRING;
BEGIN
lx := LENGTH(x); ly := LENGTH(y);
FOR i:=1 TO lx + ly DO s[i] := 0;
FOR i:=1 TO lx DO VAL(COPY(x, lx + 1 - i, 1), a[i], k);
FOR i:=1 TO ly DO VAL(COPY(y, ly + 1 - i, 1), b[i], k);
FOR i:=1 TO lx DO BEGIN
FOR j:=1 TO ly DO BEGIN
d := a[i] * b[j]; v := i + j - 1;
s[v] := s[v] + d MOD 10;
s[v + 1] := s[v + 1] + s[v] DIV 10 + d DIV 10;
s[v] := s[v] MOD 10;
END;
END;
IF s[lx + ly] = 0 THEN l := lx + ly - 1 ELSE l := lx + ly;
z := '';
FOR i:=l DOWNTO 1 DO BEGIN
STR(s[i], zz);
z := z + zz;
END;
gjdmult := z;
END;
VAR
i: INTEGER; m, n: BYTE; l, m0: STRING;
BEGIN
READLN(m, n); l := '1'; STR(m, m0);
FOR i:=1 TO n DO BEGIN
l := gjdmult(l, m0);
END;
WRITELN(l);
END.
板凳
编程小菜菜 [专家分:90] 发布于 2007-08-01 10:46:00
哎!Matodied就是厉害,啥都知道,有那么喜欢帮菜菜们..
3 楼
迷路的天使 [专家分:1340] 发布于 2007-11-20 19:19:00
不懂
我来回复