Cod sursa(job #3212696)

Utilizator Razvan23Razvan Mosanu Razvan23 Data 12 martie 2024 08:58:33
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("ciur.in");
ofstream fout("ciur.out");

bitset<2000005> fr;
int n;

int main()
{
    ios_base::sync_with_stdio(0);
    fin.tie(0);
    fout.tie(0);
    int i, j;
    fr[0] = fr[1] = 1;
    for(i=2; i*i<=2000000; i++)
        if(fr[i] == 0)
            for(j=2; j*i<=2000000; j++)
                fr[i*j] = 1;
    fin >> n;
    int nr = 0;
    for(i=2; i<=n; i++)
        if(fr[i] == 0) nr++;
    fout << nr;
    fin.close();
    fout.close();
    return 0;
}