Cod sursa(job #2076698)
Utilizator | Data | 26 noiembrie 2017 22:31:48 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
unsigned v[2000000], n, k, p;
int main()
{
fin >> n;
for (unsigned i = 0; i <= n; i++)
{
v[i] = 1;
}
v[0] = 0;
v[1] = 0;
for (p = 2; p <= sqrt(n); p++)
{
if (v[p] == 1)
{
for (unsigned j = 2; j * p <= n; j++)
{
v[p * j] = 0;
}
}
}
for (unsigned i = 0; i <= n; i++)
if (v[i] == 1) k++;
fout << k;
fout.flush();
return 0;
}