Cod sursa(job #861897)
| Utilizator | Data | 21 ianuarie 2013 23:28:20 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <iostream>
#include <cstdio>
#include <bitset>
using namespace std;
#define Nmax 2000000
int n, nr;
bitset <Nmax> ciur;
void gen(){
for(int i = 2; i <= n; i++)
if(!ciur[i]){
nr++;
for(int j = i + i; j <= n; j += i)
ciur[j] = 1;
}
}
void citire(){
freopen("ciur.in", "r", stdin);
scanf("%d", &n);
}
void afis(){
freopen("ciur.out", "w", stdout);
printf("%d\n", nr);
}
int main(){
citire();
gen();
afis();
return 0;
}
