那边的时限是25s!
下面有一个程序,输出应该没有问题,而且在25s内一定能出解
这不是自己写的
label ext,ext2;
const
dn=6890;
var
i,ip,c:integer;
k:longint;
a,b,sum:array[1..dn] of integer;
procedure oupt;
var i:integer;
k:longint;
procedure testk;
begin
end;
begin
k:=0;
write(sum[1],'.');
for i:=2 to dn do
begin
write(sum[i] div 1000); k:=k+1; testk;
write(sum[i] div 100 mod 10); k:=k+1; testk;
write(sum[i] div 10 mod 10 ); k:=k+1; testk;
write(sum[i] mod 10); k:=k+1; testk;
end;
end;
procedure m_div(k:longint);
var
i:integer;
r1,c:longint;
begin
c:=0;
for i:=ip to dn do
begin
r1:=c*10000+a[i];
a[i]:=r1 div k;
c:=r1 mod k;
end;
end;
procedure m_div2(k:longint);
var
i:integer;
r1,c:longint;
begin
c:=0;
{ for i:= ip-1 downto 1 do b[i]:=0; }
for i:=ip to dn do
begin
r1:=c*10000+a[i];
b[i]:=r1 div k;
c:=r1 mod k;
end;
end;
procedure sum_add;
var
i:integer;
r1,c:longint;
begin
c:=0;
for i:= dn downto ip do
begin
r1:=c+b[i]+sum[i];
if r1>9999 then
begin
sum[i]:=r1 - 10000;
c:=1;
end
else
begin
sum[i]:=r1;
c:=0;
end;
end;
if c=0 then exit;
i:=ip-1;
while c>0 do
begin
if i=1 then
begin
sum[1]:=c+sum[1];
exit;
end
else
begin
r1:=c+sum[i];
if r1>9999 then
begin
sum[i]:=r1 - 10000;
c:=1;
end
else
begin
sum[i]:=r1;
c:=0;
end;
end;
i:=i-1;
end;
end;
procedure sum_sub;
var
i:integer;
r1,c:longint;
begin
c:=0;
for i:= dn downto ip do
begin
r1:=c-b[i]+sum[i];
if r1<0 then
begin
sum[i]:=r1+10000;
c:=-1;
end
else
begin
sum[i]:=r1;
c:=0;
end;
end;
if c=0 then exit;
i:=ip-1;
while c<0 do
begin
if i=1 then
begin
sum[1]:=c+sum[1];
exit;
end
else
begin
r1:=c+sum[i];
if r1<0 then
begin
sum[i]:=r1+10000;
c:=-1;
end
else
begin
sum[i]:=r1;
c:=0;
end;
end;
i:=i-1;
end;
end;
procedure proc;
var
r1,c:longint;
i:integer;
begin
c:=0;
for i:=dn downto 1 do
begin
r1:=1;
r1:=c+r1*sum[i]*4;
if r1>9999 then
begin
sum[i]:=r1 mod 10000;
c:=r1 div 10000;
end
else
begin
sum[i]:=r1;
c:=0;
end;
end;
end;
begin
assign(output,'pi.txt');
rewrite(output);
for i:=1 to dn do sum[i]:=0;
a:=sum;
a[1]:=20;
k:=1;
ip:=1;
c:=1;
repeat
i:=ip;
while a[i]=0 do
begin
i:=i+1;
if i>dn then goto ext;
end;
ip:=i;
m_div(25);
m_div2(k);
if c=1 then sum_add
else sum_sub;
k:=k+2;
c:=-c;
until false;
ext:
for i:=1 to dn do a[i]:=0;
a[1]:=239;
b:=a;
k:=1;
ip:=1;
c:=-1;
repeat
i:=ip;
while a[i]=0 do
begin
i:=i+1;
if i>dn then goto ext2;
end;
ip:=i;
m_div(57121);
m_div2(k);
if c=1 then sum_add
else sum_sub;
k:=k+2;
c:=-c;
until false;
ext2:
proc;
oupt;
close(output);
end.