Cod sursa(job #514244)

Utilizator vendettaSalajan Razvan vendetta Data 18 decembrie 2010 08:59:47
Problema Ciurul lui Eratosthenes Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.76 kb
const f='ciur.in';g='ciur.out';
    nmax=100000000;
var
    v:array[1..nmax] of char;
    n,i,j,cate:longint;
begin
    assign(input,f);reset(input);
    assign(output,g);rewrite(output);
    read(n);
    //cate:=1;
    i:=1;
    for i:=1 to n do v[i]:='0';
    while ((i*i) shl 1)+(i shl 1)<=n do
        begin
        if v[i]='0' then
            begin
            j:=((i*i) shl 1)+(i shl 1);
            while (j shl 1)+1 <=n do
                begin
                v[j]:='1';
                j:=j+(i shl 1)+1;
                end;
            end;
        i:=i+1;
        end;
    i:=1;
    while 2*i+1<=n do
        begin
        if v[i]='0' then inc(cate);
        i:=i+1;
        end;
    write(cate);
    close(input);close(output);
end.