Cod sursa(job #2809377)
Utilizator | Data | 26 noiembrie 2021 20:00:23 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
using namespace std;
ifstream cin("ciur.in");
ofstream cout("ciur.out");
bool v[2000000], n;
int main() {
cin >> n;
v[0] = 1;
v[1] = 1;
for (int i = 2; i * i <= n; ++i) {
if (v[i] == 0)
for (int k = 2; k <= n / i; ++k) {
v[i * k] = 1;
}
}
int c = 0;
for (int i = 2; i <= n; ++i)
if (v[i] == 0)
c++;
cout << c;
return 0;
}