Cod sursa(job #509265)
| Utilizator | Data | 10 decembrie 2010 19:19:09 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std ;
const int MAXN = 2000000 ;
bool binar [ MAXN ] ;
int n , k ;
int main ( )
{
freopen ( "ciur.in" , "r" , stdin ) ;
freopen ( "ciur.out" , "w" , stdout ) ;
cin >> n ;
int i , j ;
for ( i = 2 ; i <= n ; ++i )
{
if ( !binar [ i ] )
{
for ( j = i << 1 ; j <= n ; j += i )
binar [ j ] = true ;
++ k ;
}
}
cout << k << endl ;
return 0 ;
}
