Cod sursa(job #1992471)

Utilizator zanugMatyas Gergely zanug Data 20 iunie 2017 15:43:47
Problema Ciurul lui Eratosthenes Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

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

const int N = 2e6+10;
bool x[N];
int n, ossz;

int main()
{
    fin >> n;
    int gyok = sqrt(n);

    x[0] = x[1] = 1;

    for(int j = 2; j <= gyok; ++j)
    {
        for(int i = 2*j; i <= n; i += j)
        {
            x[i] = 1;
        }
    }

    for(int i = 0; i <= n; ++i)
        if(x[i] == 0)
            ++ossz;

    fout << ossz;

    return 0;
}