Cod sursa(job #1691881)
| Utilizator | Data | 19 aprilie 2016 18:06:15 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 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(long long j = i * i; j <= n; j += 2 * i){
v[j] = true;
}
}
}
}
int main(){
int n;
fin >> n;
Ciur(n);
fout << ans;
return 0;
}
