Cod sursa(job #2285126)

Utilizator cristina_ovidiuCristina Ovidiu Lucian cristina_ovidiu Data 18 noiembrie 2018 10:46:56
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <bits/stdc++.h>

using namespace std;

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

bool x[2000001];

int main()
{
    int s = 1, n, rad;
    in >> n;
    rad = sqrt((double) n) + 1;
    for(int i = 3; i <= rad; i += 2)
        if(x[i] == 0)
            for(int j = i * i; j <= n; j += i)
                x[j] = 1;
    for(int i = 3; i <= n; i += 2)
        if(!x[i])
            s++;
    out << s;
    return 0;
}