Cod sursa(job #1562872)
Utilizator | Data | 5 ianuarie 2016 15:46:16 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
const int MAX = 3e6 ;
bool v [ MAX ] ;
int solve ( int n )
{
int sol = 0 ;
for ( int i = 2 ; i <= n ; ++ i )
{
if ( v [ i ] == 0 ) /// e prim
{
++ sol ;
for ( int j = i + i ; j <= n ; j += i )
v [ j ] = 1 ;
}
}
return sol ;
}
int main()
{
int n ;
cin >> n ;
cout << solve ( n ) ;
return 0;
}