Cod sursa(job #2436685)
| Utilizator | Data | 6 iulie 2019 18:06:06 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const long long nmax = 2000001;
int i, j, n, nr = 2000001, ans, ciur[nmax];
void eratostene()
{
ciur[0] = 1;
ciur[1] = 1;
for(i = 2; i <= int(sqrt(nr)); ++i)
if(ciur[i] == 0)
for(j = 2; j <= nr/i; ++j)
ciur[i*j] = 1;
}
int main()
{
fin >> n;
eratostene();
for(int i = 2; i <= n; ++i)
if(ciur[i] == 0)
ans++;
fout << ans;
return 0;
}
