Cod sursa(job #1989788)
| Utilizator | Data | 8 iunie 2017 21:56:55 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <iostream>
#include <fstream>
#include <vector>
int main() {
std::ifstream fileIn("ciur.in");
std::ofstream fileOut("ciur.out");
int nV, nCount;
fileIn >> nV;
nV++;
std::vector<bool> check(nV, true);
check[2] = true;
for (int i(2); i < nV; i++) {
if (check[i]) {
nCount++;
for (int j(i + i); j < nV; j += i) {
check[j] = false;
}
}
}
fileOut << nCount;
fileIn.close();
fileOut.close();
return 0;
}
