Cod sursa(job #2175788)
Utilizator | Iulian Oleniuc IulianOleniuc | Data | 16 martie 2018 18:59:47 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
#define SMAX 2000010
std::ifstream fin("ciur.in");
std::ofstream fout("ciur.out");
int n, sol;
bool sieve[SMAX];
void erat() {
for (int i = 2; i * i <= n; i++)
if (!sieve[i])
for (int j = i * i; j <= n; j += i)
sieve[j] = true;
sol = 1;
for (int i = 3; i <= n; i += 2)
if (!sieve[i])
sol++;
}
int main() {
fin >> n;
erat();
fout << sol << '\n';
fout.close();
return 0;
}