Cod sursa(job #1992518)

Utilizator zanugMatyas Gergely zanug Data 20 iunie 2017 17:09:04
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 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()
{
    cin >> n;
    int gyok = sqrt(n);

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

    for(int i = 4; i <= n; i += 2)
        x[i] = 1;

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

    }

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


    cout << "\n" << ossz;

    return 0;
}