iliya785

eratosthenes_sieve

May 22nd, 2012
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.34 KB | None | 0 0
  1. var
  2.     a:array of boolean;
  3.     i,j,n,m:longint;
  4.  
  5. Begin
  6.   read(n,m);
  7.   SetLength(a,m+1);
  8.   for i:=2 to m do
  9.     a[i]:=true;
  10.   for i:=2 to trunc(sqrt(m)) do
  11.     if a[i] then
  12.        begin
  13.          j:=sqr(i);
  14.          while (j<=m) do
  15.            begin
  16.              a[j]:=false;
  17.              inc(j,i);
  18.            end;
  19.        end;
  20. end.
Advertisement
Add Comment
Please, Sign In to add comment