Cod sursa(job #2460497)

Utilizator VanillaSoltan Marian Vanilla Data 23 septembrie 2019 20:01:40
Problema Ciurul lui Eratosthenes Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.89 kb
var b,n,i,p,last,count:longint;
este:boolean;
var x:array[1..2001000] of boolean;
fin,fout:textfile;
begin
assign(fin,'ciur.in');
reset(fin);
assign(fout,'ciur.out');
rewrite(fout);
readln(fin,n);
p:=2;
i:=2;
x[1]:=True;
x[2]:=False;
while este=false do begin
    while i<=n do begin
    i:=i+p;
   // writeln('i=',i);
        if x[i]=false then count:=count+1 ;
        x[i]:=True;       
    end;
    if count=0 then este:=true;
    count:=0;
    for i:=p to n do begin
        if (i>p) and (x[i]=False) then begin
          //  writeln('p=',p);
            p:=i;
            break;
            end;
        end;
        i:=p;
        end;
{for i:=1 to n do 
   if n mod i=0 then 
      inc(a);  
   if a=2 then x[n]:=false  
   else x[n]:=true;}
for i:=1 to n do 
    if x[i]=false then inc(b);
writeln(fout,b);
close(fin);
close(fout);
end.