Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Lab_2_2;
- {$APPTYPE CONSOLE}
- {$R *.res}
- Uses
- System.SysUtils;
- Type
- TArr = Array Of ShortInt;
- Var
- ArrayOfCorrect: TArr;
- N: ShortInt;
- Function InputNumber(): ShortInt;
- Const
- MAX_NUMBER = 127;
- MIN_NUMBER = 2;
- Var
- Number: ShortInt;
- IsCorrect: Boolean;
- Begin
- Repeat
- Writeln ('Введите натуральное число N в диапазоне от ', MIN_NUMBER,' до ', MAX_NUMBER);
- IsCorrect := True;
- Try
- Readln (Number);
- Except
- Writeln ('Данные введены некорректно');
- IsCorrect := False;
- End;
- If ((IsCorrect) And ((Number < MIN_NUMBER) Or (Number > MAX_NUMBER))) Then
- Begin
- Writeln ('Введено число неверного диапазона');
- IsCorrect := False;
- End
- Until (IsCorrect);
- InputNumber := Number;
- End;
- Function ConsistencyUpToNumber(Number: ShortInt): TArr;
- Var
- I: Integer;
- ArrNumbers: TArr;
- Begin
- SetLength (ArrNumbers, Number - 1);
- I := 0;
- While (I < Number - 1) Do
- Begin
- ArrNumbers[I] := I + 2;
- Inc(I);
- End;
- ConsistencyUpToNumber := ArrNumbers;
- End;
- Function SecondDivision(ArrNumbersElement: ShortInt; Quotient: Integer): ShortInt;
- Const
- ArrOfPrime: Array[0..17] Of Integer = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61);
- Var
- K, ArrCorrectnessElement: Integer;
- Begin
- K := 0;
- While ((K < 18) And (ArrOfPrime[K] <= Quotient)) Do
- Begin
- If (Quotient = ArrOfPrime[K]) Then
- Begin
- ArrCorrectnessElement := ArrNumbersElement;
- K := 18;
- End
- Else
- Begin
- ArrCorrectnessElement := 0;
- Inc (K);
- End;
- End;
- SecondDivision := ArrCorrectnessElement;
- End;
- Function FindingRequiredNumbers(Number: ShortInt): TArr;
- Const
- ArrOfPrime: Array[0..17] Of Integer = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61);
- Var
- I, K, Quotient: Integer;
- ArrCorrectness: TArr;
- ArrNumbers: TArr;
- Begin
- ArrNumbers := ConsistencyUpToNumber(Number);
- Dec(Number);
- SetLength (ArrCorrectness, Number);
- Dec(Number);
- For I := 0 To Number Do
- Begin
- K := 0;
- While ((K < 18) And (ArrOfPrime[K] < ArrNumbers[I])) Do
- Begin
- If (ArrNumbers[I] Mod ArrOfPrime[K] = 0) Then
- Begin
- Quotient := ArrNumbers[I] Div ArrOfPrime[K];
- ArrCorrectness[I] := SecondDivision(ArrNumbers[I], Quotient);
- K := 18;
- End;
- Inc (K);
- End;
- End;
- FindingRequiredNumbers := ArrCorrectness;
- End;
- Procedure NumberOutput(Number: ShortInt; ArrCorrect: TArr);
- Var
- ZeroValue, I: Integer;
- Begin
- Writeln ('Полученные натуральные числа:');
- Dec(Number);
- ZeroValue := Number;
- For I := 0 To Number Do
- If (ArrCorrect[I] <> 0) Then
- Begin
- Write (ArrCorrect[I], ' ');
- Dec(ZeroValue);
- End;
- If (ZeroValue = Number) Then
- Write ('Натуральные числа, соответствующие требованиям, не найдены');
- End;
- Procedure WriteTask ();
- Begin
- Writeln ('Данная программа находит все натуральные числа, которые можно представить в виде произведения двух простых чисел и которые не превосходят введённое натуральное число N');
- End;
- Begin
- WriteTask;
- N := InputNumber;
- ArrayOfCorrect := FindingRequiredNumbers(N);
- NumberOutput(N, ArrayOfCorrect);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement