Cod sursa(job #2966422)
Utilizator | Data | 17 ianuarie 2023 16:27:05 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int main()
{
int n, contor = 0;
char v[2000005];
fin >> n;
for(int i = 2; i <= n; ++i) {
v[i] = 1;
}
for(int i = 2; i <= n; ++i) {
if(v[i]) {
contor++;
for(int j = i + i; j <= n; j += i) {
v[j] = 0;
}
}
}
fout << contor;
return 0;
}