Cod sursa(job #2376155)

Utilizator danhHarangus Dan danh Data 8 martie 2019 13:51:46
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <bitset>
#include <cmath>
#include <fstream>
using namespace std;

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

const int MAX =   2000000 + 10;

bitset<MAX>p;

int nrP = 1;

int main()
{
    int i, j, n;
    fin>>n;
    p[1] = 1;
    for(i=3; i<=n; i+=2)
    {
        if(!p[i])
        {
            nrP++;
            for(j=i*i; j<=n; j+=(2*i))
            {
                p[j] = 1;
            }
        }
    }


    fout<<nrP;
    fin.close();
    fout.close();
    return 0;
}