Cod sursa(job #1732233)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 21 iulie 2016 10:52:43
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f ("ciur.in");
ofstream t ("ciur.out");

long n;
bool v[2000010];

void sift(long x)
{
    for (long i=x*x; i<=n; i+=x)
        v[i]=true;
}

long magic()
{
    long s=0;
    for (long i=2; i<=n; ++i)
    {
        if (!v[i])
            ++s;
        sift(i);
    }
    return s;
}

int main()
{
    f>>n;
    t<<magic();
    return 0;
}