Cod sursa(job #2926906)
Utilizator | Data | 18 octombrie 2022 21:58:45 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int maxn = 2000001;
bool ciur[maxn];
void eratostene() {
ciur[0] = ciur[1] = 1;
for (int i = 2; i * i < maxn; i++)
if (!ciur[i])
for (int j = i * i; j < maxn; j += i)
ciur[j] = true;
}
int main() {
eratostene();
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n;
fin >> n;
int nrprim = 0;
for (int i = 2; i <= n; i++)
nrprim += !ciur[i];
fout << nrprim;
return 0;
}