Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils, Math;
- const
- ErrorMessage = 'Error! P should be natural number from 1 to 2147483647';
- type
- TArray = array of Integer;
- procedure EnterP(var P : Integer);
- var
- Input : string;
- IsCorrect : Boolean;
- begin
- IsCorrect := False;
- repeat
- try
- Writeln('Enter P');
- Readln(Input);
- P := StrToInt(Input);
- if P < 1 then
- Writeln(ErrorMessage)
- else
- IsCorrect := True
- except
- Writeln(ErrorMessage);
- end;
- until IsCorrect;
- end;
- function GetSumOfDividers(N : Integer) : Integer;
- var
- i, Last, Sum: Integer;
- begin
- Sum := 1;
- Last := Trunc(Sqrt(N));
- Write('1, ');
- for i := 2 to Last do
- if N mod i = 0 then
- begin
- if i*i = N then
- begin
- Sum := Sum + i;
- Write(i, ' ');
- end
- else
- begin
- Sum := Sum + i + (N div i);
- Write(i, ' + ', N div i, ', ');
- end;
- end;
- Writeln('(', Sum, ')');
- GetSumOfDividers := Sum;
- end;
- function IsPerfect(N : Integer) : Boolean;
- begin
- if N = GetSumOfDividers(N) then
- IsPerfect := True
- else
- IsPerfect := False;
- end;
- procedure Main;
- var
- P, i, x: Integer;
- begin
- Writeln('This program finds all ''perfect'' numbers less than P');
- EnterP(P); -
- x := GetSumOfDividers(P);
- {for i := 1 to P do
- if IsPerfect(i) then
- Writeln(i);
- }
- Readln;
- end;
- begin
- Main;
- end.
Add Comment
Please, Sign In to add comment