Cod sursa(job #2367319)
| Utilizator | Data | 5 martie 2019 10:10:28 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <iostream>
#include <bitset>
using namespace std;
ifstream fin ("ciur.in");
ofstream fout ("ciur.out");
int n;
bitset <2000002> sieve;
void CreateSieve ()
{
int i, j;
sieve[0] = sieve[1] = 1;
for (i = 4; i <= n; i += 2)
sieve[i] = 1;
for (i = 3; i * i <= n; i += 2)
if (!sieve[i])
for (j = i * i; j <= n; j += 2 * i)
sieve[j] = 1;
}
int main()
{
fin >> n;
CreateSieve();
fout << n - sieve.count() + 1 << "\n";
return 0;
}
