Cod sursa(job #2691766)
Utilizator | Popescu Serban SerbaP123 | Data | 29 decembrie 2020 22:17:05 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
#define nmax 1000000
using namespace std;
ifstream cin("ciur.in");
ofstream cout("ciur.out");
int v[nmax];
void ciur(int n){
v[0] = 1, v[1] = 1;
for(int i = 2; i * i <= nmax; ++i){
if(v[i] == 0){
for(int j = 2; i * j <= nmax; ++j){
v[i * j] = 1;
}
}
}
}
int main(){
int n, cnt = 0;
cin >> n;
ciur(nmax);
for(int i = 1; i <= n; ++i){
if(v[i] == 0){
cnt++;
}
}
cout << cnt;
return 0;
}