Cod sursa(job #2649242)

Utilizator baragan30Baragan Andrei baragan30 Data 13 septembrie 2020 17:56:25
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");
bool v[2000*1000+1];///0 daca e prim , 1 daca nu e prim

int change_v(int n ){
    v[1] = 1;
    int count_v = 0;
    for (int i = 2 ; i <= n ; i ++)
    {
        if (v[i] == 0)
        {
            count_v++;
            for (long long j = 2 * i; j <= n ; j += i )
            {
                v[j] = 1;
            }
        }
    }
    return count_v;
}

int main() {
    int n;
    f >> n;
    g << change_v(n);



    return 0;
}