Cod sursa(job #1254888)
Utilizator | Data | 3 noiembrie 2014 17:58:05 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 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);
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;
}