Cod sursa(job #604510)
| Utilizator | Data | 22 iulie 2011 21:39:10 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#define NMax 2000005
using namespace std;
int N, NPrime;
bool V[NMax];
void Eratosthenes ()
{
for (int i=2; i<=N; ++i)
{
if (!V[i])
{
++NPrime;
for (int j=i+i; j<=N; j+=i)
{
V[j]=true;
}
}
}
}
int main()
{
freopen ("ciur.in", "r", stdin);
freopen ("ciur.out", "w", stdout);
scanf ("%d", &N);
Eratosthenes ();
printf ("%d\n", NPrime);
return 0;
}
