Cod sursa(job #153383)
| Utilizator | Data | 10 martie 2008 15:01:47 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <stdio.h>
#include <fstream>
using namespace std;
#define in "ciur.in"
#define out "ciur.out"
#define dim 2000001
int N;
int Nr[1001];
bool Sel[dim];
int main()
{
int size = 0, total = 1;
freopen(in,"r",stdin);
freopen(out,"w",stdout);
scanf("%d", &N);
memset(Sel,0,sizeof(Sel));
for ( int i = 2; i*i <= N; i++ )
{
if ( Sel[i] ) continue;
for ( int j = 2; i*j <= N; j++ )
{
if ( !Sel[i*j] ) total++;
Sel[i*j] = 1;
}
}
total = N - total;
printf("%d\n",total);
}
