Advertisement
mrlolthe1st

Untitled

Nov 15th, 2021
1,272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.66 KB | None | 0 0
  1. Const
  2.     N = 10000000;
  3. Var
  4.     Pr, Lp : Array [2 .. N] Of LongInt;
  5.     I, J, P : LongInt;
  6. Begin
  7.     Lp[2] := 2;
  8.     P := 0;
  9.     For I := 2 To N Do
  10.     Begin
  11.         If (Lp[I] = 0) Then
  12.         Begin
  13.             Lp[I] := I;
  14.         End;
  15.        
  16.         If Lp[I] = I Then
  17.         Begin
  18.             Inc(P);
  19.             Pr[P] := I;
  20.         End;
  21.        
  22.         For J := 1 To P Do
  23.         Begin
  24.             If (Lp[I] < Pr[J]) Or (I * Pr[J] > N) Then
  25.             Begin
  26.                 Break;
  27.             End;
  28.             Lp[I * Pr[J]] := Pr[J];
  29.         End;
  30.     End;
  31.     For I := 1 To P Do
  32.     Begin
  33.         Write(Pr[I], ' ');
  34.     End;
  35. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement