Cod sursa(job #3214163)

Utilizator mihaihvhTuburlui Mihai mihaihvh Data 13 martie 2024 20:51:25
Problema Ciurul lui Eratosthenes Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

using namespace std;

ifstream cin("ciur.in");
ofstream cout("ciur.out");

int v[2000001];

int main() {
    int n;
    cin >> n;
    v[0] = 1;
    v[1] = 1;
    int cnt = 0;
    for (int i = 2; i <= n; ++i) {
        for (int j = i+i; j <= n; j += i)
            if (v[j] == 0) {
                v[j] = 1;
            }
        if (v[i] == 0)
            ++cnt;
    }
    cout << cnt;

    return 0;
}