blank space百度网盘:pascal编程求正整数A和B之间的完全数

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 20:33:59

program l_1(input,output);
type
cc=record
data,total:integer;
end;
var
a,b,i,he:integer;
bt:array[1..1000] of cc;
function fac(a:integer):integer;
var
i:integer;
begin
fac:=0;
for i:=1 to a-1 do
if a mod i=0 then fac:=fac+i;
end;
begin
he:=0;
assign(input,'work1_3.in');
reset(input);
assign(output,'work1_3.out');
rewrite(output);
readln(a,b);
for i:=a to b do
begin
bt[i-a+1].data:=i;
bt[i-a+1].total:=fac(i);
if fac(i)=i then inc(he);
end;
writeln(he);
for i:=1 to b-a+1 do
if bt[i].data=bt[i].total then writeln(bt[i].data);
close(input);
close(output);
end.

都是枚举
若比n小的正因数之和等于n,则n称为完全数