Cod sursa(job #1373629)
Utilizator | Data | 4 martie 2015 19:48:01 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
using namespace std;
const int kXMax = 2000010;
int x, sol;
bool viz[kXMax];
void Citire() {
ifstream in("ciur.in");
in >> x;
in.close();
}
void Solve() {
if(x >= 2)
sol = 1;
for (int i = 3; i <= x; i += 2)
if(!viz[i]) {
sol++;
for (int j = i; j <= x; j += i)
viz[j] = 1;
}
}
void Afisare() {
ofstream out("ciur.out");
out << sol << '\n';
out.close();
}
int main() {
Citire();
Solve();
Afisare();
}