3的N次方的PASCAL编程做法

来源:百度知道 编辑:UC知道 时间:2024/06/07 09:52:09
高精度

var a:array[0..10000] of longint;
i,j,n:longint;
begin
readln(n);
a[0]:=1;
a[a[0]]:=1;
for i:=1 to n do
begin
for j:=a[0] downto 1 do
begin
a[j]:=a[j]*3;
a[j+1]:=a[j+1]+a[j] div 10000;
a[j]:=a[j] mod 10000;
end;
if a[a[0]+1]>0 then
inc(a[0]);
end;
write(a[a[0]]);
for i:=a[0]-1 downto 1 do
begin
if a[i]<1000 then
write(0);
if a[i]<100 then
write(0);
if a[i]<10 then
write(0);
write(a[i]);
end;
end.
高精压4位。。数据再大也基本不会超

做N次的高精度乘3就可以了

type arr=array[1..200] of integer;
var i,j,n:longint;
a:arr;

function mul(a:arr):arr;
var i,len:longint; temp:arr;
begin
i:=200;
while (a[i]=0) do dec(i);

len:=i;
fillchar(temp,sizeof(temp),0);
for i:=1 to len do begin