Cod sursa(job #2299622)
Utilizator | Darius Capolna DariusDC | Data | 9 decembrie 2018 20:05:09 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int NMAX = 2000005;
short ciur[NMAX];
int n;
void eratostene()
{
int nr = 0;
for (int d=2;d<=n;d++)
{
if (ciur[d] == 0)
{
nr++;
int x = d;
while (x <= n)
{
x = x + d;
ciur[x] = 1;
}
}
}
fout << nr;
}
int main()
{
fin >> n;
eratostene();
return 0;
}