Cod sursa(job #431155)

Utilizator SpiderManSimoiu Robert SpiderMan Data 31 martie 2010 18:39:02
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.62 kb
program ciur;
const MAX = 1 shl 17;
var v:array[0..MAX] of longint;
    n,i,j,rez:longint;
    f,g:text;
  begin
   assign(f,'ciur.in');reset(f);
   assign(g,'ciur.out');rewrite(g);

   readln(f,n);

   i:=3;
   while (i <= N) do
    begin
     if (V[i shr 5] and (1 shl (i and 31)) <> 0) then
      begin
       i := i + 2;
       continue;
      end;
     inc(rez);
     j := i + (i shl 1);
     while (j <= N) do
      begin
       V[j shr 5] := V[j shr 5] or (1 shl (j and 31));
       j := j + (i shl 1);
      end;
     i := i + 2;
    end;
  writeln(g,rez + 1);
  close(f);
  close(g);
 end.