如何用Pascal找2-1000中的亲密数对

来源:百度知道 编辑:UC知道 时间:2024/05/12 11:19:05
找2-1000中的亲密数对(如果a的因子和等于b,b的因子和等于a,且a≠b,则称a,b为亲密数对)

var
i,a,he,b:longint;
begin
for a:=2 to 1000 do
begin
he:=1;
for i:=2 to trunc(sqrt(a)) do
if a mod i=0 then
he:=he+i+a div i;{he 是a的因数和}
b:=1;
for i:=2 to trunc(sqrt(he)) do
if he mod i=0 then
b:=b+i+he div i;{b 是he的因数和}
if (a=b)and(a<he){防止重复} then
writeln(a:6,he:6);
end;
end.
答案是220和284