Cod sursa(job #1254903)
Utilizator | Data | 3 noiembrie 2014 18:11:03 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
#include <vector>
using namespace std;
ifstream is("ciur.in");
ofstream os("ciur.out");
int n, nr;
vector<int> x;
int main()
{
is >> n;
x = vector<int>(n+1, 1);
x[1] = 0;
for ( int i = 2; i * i <= n; i++ )
if ( x[i] )
for ( int j = 2; i * j <= n; j++ )
x[i * j] = 0, nr++;
os << n - nr;
is.close();
os.close();
return 0;
}