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 ArrayOfIntegers (Number: ShortInt): TArr;
- Var
- I: Integer;
- ArrNumbers: TArr;
- Begin
- Dec(Number);
- SetLength (ArrNumbers, Number);
- For I := 0 To Number Do
- ArrNumbers[I] := I + 2;
- ArrayOfIntegers := ArrNumbers;
- 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 := ArrayOfIntegers (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];
- K := 0;
- While (K < 18) And (ArrOfPrime[K] <= Quotient) Do
- Begin
- If (Quotient = ArrOfPrime[K]) Then
- Begin
- ArrCorrectness[I] := 1;
- K := 18;
- End
- Else
- Begin
- ArrCorrectness[I] := 0;
- Inc (K);
- End;
- End;
- End
- Else
- Inc (K);
- End;
- End;
- FindingRequiredNumbers := ArrCorrectness;
- End;
- Procedure NumberOutput(Number: ShortInt; ArrCorrect: TArr);
- Var
- ArrNumbers: TArr;
- ZeroValue, I: Integer;
- Begin
- Writeln ('Полученные натуральные числа:');
- ArrNumbers := ArrayOfIntegers (Number);
- Dec(Number);
- ZeroValue := 0;
- For I := 0 To Number Do
- Begin
- If (ArrCorrect[I] = 1) Then
- Write (ArrNumbers[I], ' ')
- Else
- Inc(ZeroValue);
- End;
- If (ZeroValue = Number) Then
- Write ('Натуральные числа, соответствующие требованиям, не найдены');
- End;
- Begin
- Writeln ('Данная программа находит все натуральные числа, которые можно представить в виде произведения двух простых чисел и которые не превосходят введённое натуральное число N');
- N := InputNumber;
- ArrayOfCorrect := FindingRequiredNumbers (N);
- NumberOutput (N, ArrayOfCorrect);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement