Cod sursa(job #2496546)

Utilizator Mihai0290Ilie Mihai-Alexandru Mihai0290 Data 20 noiembrie 2019 23:39:34
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    int n;
    ifstream in("ciur.in");
    ofstream out("ciur.out");
    in >> n;
    long long int nr = 0;
    char v[2000000] = {0};
    v[0] = v[1] = 1;
    for(int i = 4; i <= n; i += 2)
    {
        v[i] = 1;
    }
    for(int i = 3; i <= n; i += 2)
    {
        if(!v[i])
        {
            nr++;
            for(int j = i * i; j <= n; j += 2 * i)
                v[j] = 1;
        }
    }
    out << ++nr;
    return 0;
}