0 bình luận về “nhập 2 số nguyên a,b(1<a<b) in ra các số hoàn hảo trong khoảng a,b”
Program vd;uses crt;var n,p:LongInt;Function kt(a:LongInt):Boolean;var i:LongInt;BeginIf a<2 then exit(false);For i:=2 to trunc(sqrt(a)) do If a mod i=0 then exit(false);exit(true);end;Beginclrscr;Write(‘Du lieu vao: ‘);Readln(n);If (n<=0) or (n>1000000) then begin Writeln(‘DU LIEU SAI’); Readln; halt; end;If n=2 then begin Writeln(‘No’); Readln; halt; end;p:=(n-1) div 2;If (kt(n)=true) and (kt(p)=true) then Writeln(‘Yes’) else Writeln(‘No’);Readln;end.
Function shh(m: longint): boolean; Var s,i: longint; Begin s:=0; For i:=1 to m div 2 do If m mod i = 0 then s:=s+i; If s=m then exit(true); exit(false); End;
Begin Clrscr; Write(‘Nhap a: ‘); Readln(a); Write(‘Nhap b: ‘); Readln(b); For i:=a to b do If shh(i) then Write(i,’ ‘); Readln End.
Program vd;uses crt;var n,p:LongInt;Function kt(a:LongInt):Boolean;var i:LongInt;BeginIf a<2 then exit(false);For i:=2 to trunc(sqrt(a)) do If a mod i=0 then exit(false);exit(true);end;Beginclrscr;Write(‘Du lieu vao: ‘);Readln(n);If (n<=0) or (n>1000000) then begin Writeln(‘DU LIEU SAI’); Readln; halt; end;If n=2 then begin Writeln(‘No’); Readln; halt; end;p:=(n-1) div 2;If (kt(n)=true) and (kt(p)=true) then Writeln(‘Yes’) else Writeln(‘No’);Readln;end.
Program NhatNgu;
Uses crt;
Var a,b,i: longint;
Function shh(m: longint): boolean;
Var s,i: longint;
Begin
s:=0;
For i:=1 to m div 2 do
If m mod i = 0 then s:=s+i;
If s=m then exit(true);
exit(false);
End;
Begin
Clrscr;
Write(‘Nhap a: ‘); Readln(a);
Write(‘Nhap b: ‘); Readln(b);
For i:=a to b do
If shh(i) then Write(i,’ ‘);
Readln
End.