Cod sursa(job #2652184)

Utilizator proflaurianPanaete Adrian proflaurian Data 24 septembrie 2020 15:35:58
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
const int N = 2000010;
bitset<N> p;
int n,np=1;
void ciur()
{
    /// marchez doar pentru valori impare
    int d;
    for(d=3;d*d<=n;d+=2)
        if(!p[d])
        {
            np++;
            for(int j=d*d;j<=n;j+=2*d)
                p[j]=1;
        }
    for( ; d<=n; d+=2)
        if(!p[d])
            np++;
    g<<np<<'\n';
}

int main()
{
    f>>n;
    if(n==2)
    {
        g<<np<<'\n';
        return 0;
    }
    ciur();
    return 0;
}