Cod sursa(job #2580802)
| Utilizator | Data | 14 martie 2020 10:47:03 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 70 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int n, nr = 1, a[2000005];
int main()
{
fin >> n;
for(int i = 4; i <= n; i += 2) a[i] = 1;
for(int i = 3; i * i <= n; i += 2)
if(a[i] == 0)
for(int j = i * i; j <= n; j = j + 2 * i)
a[j] = 1;
for(int i = 3; i <= n; i+=2) if(a[i] == 0) nr++;
fout << nr;
return 0;
}
