比赛 暑假培训一 评测结果 EEEEEEEEEE
题目名称 麦森数 最终得分 0
用户昵称 sywgz 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-17 11:28:02
显示代码纯文本
Program Mason;

Type
sc=array [0..5000] of longint;

Var
p,l:longint;
c,i,j:integer;
k,h,ans:sc;
f1,f2:text;

Begin
assign(f1,'Mason.in');
reset(f1);
assign(f2,'Mason.out');
rewrite(f2);
read(f1,p);
l:=(trunc(p*ln(2)/ln(10)))+1;
k[0]:=2; ans[0]:=1;
for i:=1 to 499 do begin
 k[i]:=0; ans[i]:=0;
end;
c:=0;

while p>0 do begin

 if p mod 2=1 then begin
  for i:=0 to 499 do h[i]:=0;
  for i:=0 to 499 do
   for j:=0 to 499 do
    h[i+j]:=ans[j]*k[i]+h[i+j];
  for i:=0 to 499 do begin
   c:=h[i] div 10;
   h[i+1]:=h[i+1]+c;
   h[i]:=h[i] mod 10;
  end;
  for i:=0 to 499 do ans[i]:=h[i];
 end;

 for i:=0 to 499 do h[i]:=0;
 for i:=0 to 499 do
  for j:=0 to 499 do
   h[i+j]:=k[j]*k[i]+h[i+j];
 for i:=0 to 499 do begin
  c:=h[i] div 10;
  h[i+1]:=h[i+1]+c;
  h[i]:=h[i] mod 10;
 end;
 for i:=0 to 499 do k[i]:=h[i];

 p:=p div 2;

end;

ans[0]:=ans[0]-1;
i:=0;
while ans[i]<0 do begin
 ans[i+1]:=ans[i+1]-10;
 ans[i]:=ans[i]+1;
 i:=i+1;
end;

writeln(f2,l);
for i:=499 downto 0 do begin
 write(f2,ans[i]);
 if i mod 50=0 then writeln(f2);
end;
close(f1);
close(f2);
End.