关于Turbo Pascal的难题19/27

来源:百度知道 编辑:UC知道 时间:2024/05/06 11:35:36
找3-1000中的亲密数对,注意不要重复显示。(如果A的因子和等于B,B的因子和等于A,且A<>B,则称A,B为亲密数对。例如284和220,220的因子有1,2,4,5,11,20,22,44,55,110,他们和为284,284的因子有1,2,4,71,112,他们和为220。

程序:
var s,i:longint;
a1,a2:int64;
bo:array[0..10000000]of boolean;

procedure expand2(a:longint);
var now,j:longint;
begin
now:=0;
for j:=1 to trunc(sqrt(a)) do
begin
if a mod j=0 then
begin
now:=now+j+a div j;
if j=1 then now:=now-a;
end;
end;
if now=i then writeln(a,' ',i);
end;

procedure expand(a:longint);
var now,i:longint;
begin
now:=0;
for i:=1 to trunc(sqrt(a)) do
begin
if a mod i=0 then
begin
now:=now+i+a div i;
if i=1 then now:=now-a;
end;
end;
if (now>a)and((not bo[now])or(now>a2)) then expand2(now);
end;

procedure make;
var i,j:longint;
begin
fillchar(bo,sizeof(bo),true);
bo[1]:=false;
for i:=1 to trunc(sqrt(a2)) do
begin
if bo[i] then
begin
for j:=2 to