Cod sursa(job #1255170)
Utilizator | Data | 4 noiembrie 2014 14:10:14 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 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)/2, 1);
for ( int i = 2; i <= n; i++ )
if ( x[i] )
{
nr++;
for ( int j = i + i; j <= n; j += i )
x[j] = 0;
}
os << nr;
is.close();
os.close();
return 0;
}