麦森数

 

 

const maxn=500;
var
    a,sta:array[0..2*maxn]of longint;
    n,len:longint;

procedure solve(n:longint); 
var i,j:longint;
begin
    if n=0 then exit; 
    solve(n div 2);  
    fillchar(sta,sizeof(sta),0);
    for i:=0 to len do
        for j:=0 to len do
            if n mod 2=0 then sta[i+j]:=sta[i+j]+a[i]*a[j]
            else  sta[i+j]:=sta[i+j]+a[i]*a[j]*2;
    for i:=0 to len do
    begin
        a[i]:=sta[i] mod 10;
        inc(sta[i+1],sta[i]div 10);
    end;
end;

procedure print;
var i:longint;
begin
    dec(a[0]);
    for i:=499 downto 0 do
        if i mod 50=0 then writeln(a[i]) else write(a[i]);
end;

begin
    readln(n);
    len:=trunc(ln(2)/ln(10)*n)+1;
    writeln(len);
    if len>500 then len:=500; 
    a[0]:=1; 
    solve(n);
    print;
end.

 

转载于:https://www.cnblogs.com/qilinart/articles/4971913.html

相关文章:

  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-11-18
  • 2022-01-22
  • 2021-09-19
  • 2021-11-25
  • 2021-06-13
猜你喜欢
  • 2022-01-15
  • 2021-06-20
  • 2021-11-28
  • 2022-02-03
  • 2022-12-23
相关资源
相似解决方案