Cod sursa(job #1674302)
Utilizator | Data | 4 aprilie 2016 16:22:22 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int NMax =2e6 + 5;
int ans;
bitset < NMax > v;
inline void Ciur(const int &n){
if(n > 2) ans++;
for(int i = 3; i <= n; i += 2){
if(!v[i]){
ans++;
for(int j = i; j <= n; j += 2 * i){
v[j] = true;
}
}
}
}
int main(){
int n;
fin >> n;
Ciur(n);
fout << ans;
return 0;
}