Cod sursa(job #2378771)
| Utilizator | Data | 12 martie 2019 16:50:20 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <iostream>
#include <fstream>
#include <math.h>
#define MAX 200004
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
bool A[MAX];
int SieveOfErathostene(int p) {
int k = 0;
for(int i = 1; i <= p; i++)
A[i] = 1;
for(int i = 2; i <= sqrt(p); i++)
if(A[i]) {
k++;
for(int j = i * i; j <= p; j = j + i)
A[j] = 0;
}
return k;
}
int main() {
int n;
in >> n;
out << SieveOfErathostene(n);
return 0;
}
