Don't like ads? PRO users don't see any ads ;-)
Guest

eratosthenes_sieve

By: iliya785 on May 22nd, 2012  |  syntax: Pascal  |  size: 0.34 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.