Cod sursa(job #1992475)
| Utilizator | Data | 20 iunie 2017 15:47:25 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int N = 2e6+10;
bool x[N];
int n, ossz;
int main()
{
cin >> n;
int gyok = sqrt(n);
x[0] = x[1] = 1;
for(int i = 4; i <= n; i += 2)
x[i] = 1;
for(int j = 3; j <= gyok && !x[j]; j += 2)
{
for(int i = 3*j; i <= n; i += 2 * j)
{
x[i] = 1;
}
}
for(int i = 0; i <= n; ++i)
if(x[i] == 0)
++ossz;
cout << ossz;
return 0;
}
