Cod sursa(job #1379747)

Utilizator pulseOvidiu Giorgi pulse Data 6 martie 2015 19:16:18
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2000010;

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

int n, cnt;
bool used[MAXN];

void ciur()
{
    for (int i = 2; i <= n; ++i)
    {
        if (!used[i])
        {
            ++cnt;
            for (int j = i + i; j <= n; j += i)
                used[j] = 1;
        }
    }
}

int main()
{
    fin >> n;
    ciur();
    fout << cnt;
    return 0;
}