pascal 求2^50000-1的最后100位
- 提问者网友:蓝莓格格巫
- 2021-04-12 19:15
- 五星知识达人网友:持酒劝斜阳
- 2021-04-12 20:26
这道题就是麦森数,你只要输入50000就行了
program xxx(input,output);
type
arr=array[1..500]of longint;
var
n,p,i,j:longint;
ans,num:arr;
function mul(a,b:arr):arr;
var
i,j:longint;
c:arr;
begin
for i:=1 to 500 do c[i]:=0;
for i:=1 to 500 do
for j:=1 to 500-i+1 do
c[i+j-1]:=c[i+j-1]+a[i]*b[j];
for i:=1 to 499 do begin
c[i+1]:=c[i+1]+c[i] div 10;
c[i]:=c[i] mod 10;
end;
c[500]:=c[500] mod 10;
mul:=c;
end;
begin
read(p);
n:=p;
ans[1]:=1;
num[1]:=2;
while p>0 do begin
if p mod 2=1 then ans:=mul(ans,num);
p:=p div 2;
num:=mul(num,num);
end;
writeln(trunc(n*ln(2)/ln(10))+1);
dec(ans[1]);
p:=1;
for i:=500 downto 1 do write(ans[i]);
end.
- 1楼网友:老鼠爱大米
- 2021-04-12 23:12
- 2楼网友:西岸风
- 2021-04-12 21:32
program xxx(input,output); type arr=array[1..500]of longint; var n,p,i,j:longint; ans,num:arr; function mul(a,b:arr):arr; var i,j:longint; c:arr; begin for i:=1 to 500 do c[i]:=0; for i:=1 to 500 do for j:=1 to 500-i+1 do c[i+j-1]:=c[i+j-1]+a[i]*b[j]; for i:=1 to 499 do begin c[i+1]:=c[i+1]+c[i] div 10; c[i]:=c[i] mod 10; end; c[500]:=c[500] mod 10; mul:=c; end; begin read(p); n:=p; ans[1]:=1; num[1]:=2; while p>0 do begin if p mod 2=1 then ans:=mul(ans,num); p:=p div 2; num:=mul(num,num); end; writeln(trunc(n*ln(2)/ln(10))+1); dec(ans[1]); p:=1; for i:=500 downto 1 do write(ans[i]); end.