Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses math, SysUtils;
- type
- IntArray = Array of Int64;
- function GetPrimes(N: Integer): IntArray;
- Var
- Ret: IntArray;
- I, J, Count: Integer;
- begin
- SetLength(Ret, N);
- for I := 0 to High(Ret) do
- Ret[I] := I + 1;
- for I := 1 to High(Ret) do
- if (Ret[I] <> 0) then
- for J := I + 1 to High(Ret) do
- if Ret[J] mod Ret[I] = 0 then
- Ret[J] := 0;
- Count := 0;
- for i := 1 to High(Ret) do
- if (Ret[i] <> 0) then
- begin
- Ret[Count] := Ret[i];
- inc(Count);
- end;
- SetLength(Ret, Count);
- GetPrimes := Ret;
- end;
- function GetN(): Byte;
- Var
- IsCorrect: Boolean;
- Ret: Integer;
- begin
- repeat
- IsCorrect := True;
- Writeln('Введите N');
- try
- Readln(Ret);
- except
- Writeln('N должно быть числом');
- IsCorrect := False;
- end;
- if (Ret < 1) or (Ret > 64) and IsCorrect then
- begin
- Writeln('N должно быть целым числом большим нуля и меньшим 65');
- IsCorrect := False;
- end;
- until IsCorrect;
- GetN := Ret;
- end;
- procedure PrintArray(ArrayToPrint: IntArray);
- var
- I: Integer;
- begin
- Writeln('Числа мерсена равны ');
- for I := 0 to High(ArrayToPrint) do
- Writeln(ArrayToPrint[I]);
- end;
- procedure GetMersennePrimes();
- var
- MersennePrimes, Primes: IntArray;
- I, N: Integer;
- begin
- N := GetN();
- Primes := GetPrimes(N);
- SetLength(MersennePrimes, Length(Primes));
- for I := 0 to High(MersennePrimes) do
- MersennePrimes[I] := Round(Power(2, Primes[I]) - 1);
- PrintArray(MersennePrimes);
- end;
- begin
- GetMersennePrimes();
- Readln;
- end.
Add Comment
Please, Sign In to add comment