Cod sursa(job #2279549)
Utilizator | Data | 9 noiembrie 2018 17:55:43 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 90 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <fstream>
using namespace std;
ifstream fi("ciur.in");
ofstream fo("ciur.out");
int n;
bool sel[2000001];
int k,p;
int main()
{
fi>>n;
p=2;
for(int i=p; i<=n; i++)
if(not sel[i])
{
p=i;
k++;
if (n / p > p)
for(int j=p*p; j<=n; j+=p)
sel[j]=true;
}
fo<<k;
return 0;
}