Advertisement
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(): Integer;
- 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.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement