Cod sursa(job #2702223)
| Utilizator | Data | 3 februarie 2021 10:57:41 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
char 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;
for (int i = 2; i <= n; ++i) {
eratosthenes[i] = '0';
}
prime(n);
return 0;
}
