Xuất ra màn hình các số hoàn hảo chia hết cho cả 3 và 9: Cái này giới hạn từ bao nhiêu đến bao nhiêu thế nhỉ? Có gì bạn xem kĩ lại đề rồi mình sẽ bổ sung vào phần trả lời nhé!
------------
Program BTT;
Uses crt;
Var n,i,t: longint;
Function ngto(a: longint): boolean;
Var i: longint;
Begin
If a<2 then exit(false);
For i:=2 to a div 2 do
If a mod i = 0 then exit(false);
exit(true);
End;
Function shh(b: longint): boolean;
Var i,s: longint;
Begin
s:=0;
For i:=1 to b div 2 do
If b mod i = 0 then s:=s+i;
If s=b then exit(true);
exit(false);
End;
Begin
Clrscr;
Write('Nhap n: '); Readln(n);
t:=0;
If ngto(n) then Write(n,' la so nguyen to')
Else Write(n,' khong phai la so nguyen to');
Writeln;
If shh(n) then Write(n,' la so hoan hao')
Else Write(n,' khong phai la so hoan hao');
Writeln;
Write('Cac so nguyen to tu 2 den n la: ');
For i:=2 to n do
If ngto(i) then
Begin
Write(i,' ');
t:=t+i;
End;
Writeln;
Write('Tong cac so nguyen to la: ',t);
Readln;
End.