Cod sursa(job #2460431)

Utilizator VanillaSoltan Marian Vanilla Data 23 septembrie 2019 18:41:48
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.8 kb
var a,b,c,d,n,i,p,count,count2,last:longint;
este:boolean;
var x:array[1..2000010] 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 n<>p do begin
    while i<n do begin
    i:=i+p;
    if i<> n then begin
        x[i]:=True;
        end;
    end;
    for i:=p to n do begin
        if (i>p) and (x[i]=False) then begin
            last:=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.