Cod sursa(job #2926673)
| Utilizator | Data | 18 octombrie 2022 13:30:41 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
using namespace std;
int v[2000001];
int main() {
int n;
cin >> n;
for (int index = 2; index * index <= n; ++index) {
int ok = 0;
if (index % 2 == 0 && index != 2 || index % 3 == 0 && index != 3) {
++ok;
}
if (ok == 0) {
for (int i = index; i * index <= n; ++i) {
v[i * index] = 1;
}
}
}
int counter = 0;
for (int index = 2; index <= n; ++index) {
if (v[index] == 0) {
++counter;
}
}
cout << counter;
}
