Cod sursa(job #3272659)
| Utilizator | Data | 30 ianuarie 2025 18:02:25 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n;
unordered_set<int> notPrime;
int main() {
fin >> n;
for (int i = 2; i <= sqrt(n) ; i++) {
if (notPrime.find(i) != notPrime.end()) {
continue;
}
int j = i * 2;
while (j <= n) {
if (notPrime.find(j) == notPrime.end()) {
notPrime.insert(j);
}
j += i;
}
}
fout << n - notPrime.size() - 1;
return 0;
}