Cod sursa(job #2267932)

Utilizator hax_m8Nicolae Antonio Cristian hax_m8 Data 24 octombrie 2018 12:11:59
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

using namespace std;

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

int v[2000005];

int main()
{
    int n, cnt = 0;
    fin >> n;
    v[0] = 1;
    v[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        for(int j = i + i; j <= n; j += i)
        {
            v[j] = 1;
        }
    }
    for (int i = 0; i < n; i++)
        if(!v[i]) cnt++;
    fout << cnt;
    return 0;
}