Cod sursa(job #463509)

Utilizator SpiderManSimoiu Robert SpiderMan Data 16 iunie 2010 10:30:02
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.12 kb
program ciur ;

const
      FIN = 'ciur.in';
      FOU = 'ciur.out';
      MAX = 1 shl 17;
var
      N, i, j, sol : longint;
      V : array [0 .. MAX] of byte;
      f : text;

   begin

      assign (f, FIN); reset (f);

      readln (f, N); close (f);

      i := 1;

      while ( i * i shl 1 ) + ( i shl 1 ) <= N do
          begin
              if ( V[i shr 3] and ( 1 shl ( i and 7 ) ) = 0 ) then
                   begin
                       j := ( i * i shl 1 ) + ( i shl 1 ) ;
                       while ( j shl 1 ) + 1 <= N do
                          begin
                              V[j shr 3] := V[j shr 3] or ( 1 shl ( j and 7 ) ) ;
                              j := j + ( i shl 1 ) + 1 ;
                          end;
                   end ;
              inc (i);
          end;

     sol := 1 ; i := 1 ;

     while ( ( i shl 1 ) + 1 <= N ) do
        begin
            if ( V[i shr 3] and ( 1 shl ( i and 7 ) ) = 0 ) then
                inc ( sol ) ;
            inc (i);
        end;

     assign (f, FOU); rewrite (f);

     writeln(f, sol);

     close(f);

  end.