Cod sursa(job #2697279)
Utilizator | Data | 18 ianuarie 2021 08:16:44 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
bool c[2000001];
int x = 2000001;
void ciur()
{
c[1]=c[0]=1;
for(int i = 2 ; i * i <= x ; ++i)
for(int j = 2 ; i * j <= x ; ++j)
c[i*j]=1;
}
int n, k;
int main()
{
f>> n;
ciur();
for(int i = 1; i <= n; i++) {
if(c[i] == 0) k++;
}
g << k;
return 0;
}