Cod sursa(job #1420650)
| Utilizator | Data | 18 aprilie 2015 19:59:58 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <bitset>
#define Nmax 2000099
#define Pmax 200000
using namespace std;
ifstream f("ciur.in");
ofstream g("ciur.out");
int N, P[Pmax];
bitset < Nmax > v;
void ciur(int N) {
P[ ++P[0] ] = 2;
for (int i = 4; i <= N; i += 2) v[i] = 1;
for(int i = 3; i <= N; i +=2)
if(!v[i]){
P[ ++P[0] ] = i;
for(int j = 2*i; j <=N ; j +=i)
if(!v[j]) v[j] = 1;
}
}
int main() {
f >> N;
ciur(N);
g << P[0] << '\n';
f.close();g.close();
return 0;
}