Cod sursa(job #3357771)
| Utilizator | Data | 13 iunie 2026 14:37:28 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
bool v[1000001];
int main()
{
int n;
in >> n;
v[0] = v[1] = true;
for (int i = 2; i * i <= n; i++)
{
if (!v[i])
{
for (int j = i * i; j <= n; j += i)
v[j] = true;
}
}
int c = 0;
for (int i = 2; i <= n; i++)
if (!v[i])
c++;
out << c;
return 0;
}