Cod sursa(job #2702219)
| Utilizator | Data | 3 februarie 2021 10:50:37 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 70 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int eratosthenes[2000001];
void prime(int n) {
int cnt = 0;
for (int i = 2; i <= n; ++i) {
if (eratosthenes[i] == 0) {
++cnt;
for (int j = i; j <= n / i; ++j) {
eratosthenes[i*j] = 1;
}
}
}
fout << cnt;
}
int main() {
int n;
fin >> n;
prime(n);
return 0;
}
