Cod sursa(job #1141952)
Utilizator | Data | 13 martie 2014 12:27:22 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <fstream>
#define nmax 2000000+5
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
bool ePrim[nmax];
int n;
int cnt;
int main()
{
int i, j;
fin >> n;
cnt = n - 1;
for (i = 2; i <= n; i++)
for (j = i * 2; j <= n; j += i)
{
if (!ePrim[j])
cnt--;
ePrim[j] = 1;
}
fout << cnt << '\n';
return 0;
}