Cod sursa(job #1017087)

Utilizator PlayLikeNeverB4George Marcus PlayLikeNeverB4 Data 27 octombrie 2013 10:25:25
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include<fstream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
fstream f("ciur.in", std::fstream::in);
ofstream g("ciur.out");
int n;


int getPrimes()
{
n++;
std::vector<bool> vec(n);
std::fill( vec.begin(), vec.end(), true );
for(int i=2;i<sqrt(n);i++){
if(vec[i]){
for(int j=pow(i,2);j<=n;j+=i){
vec[j]=false;
}
}
}

int result =0;
for(int i=2;i<n;i++){
if(vec[i])
{result++;}
}
return result;
}

int main()
{
f>>n;
g<<getPrimes();

return 0;
}