Cod sursa(job #2908168)
Utilizator | Data | 1 iunie 2022 21:43:17 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
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");
int n, cnt;
bool ciur[2000001];
void eratostene();
int main() {
cin >> n;
cnt = 1;
eratostene();
cout << cnt;
return 0;
}
void eratostene() {
for (int i = 3; i <= n; i += 2) {
if (!ciur[i]) {
cnt++;
for (int j = 2; i * j <= n; j++) ciur[i * j] = 1;
}
}
}