Cod sursa(job #3377035)
| Utilizator | Data | 21 noiembrie 2026 12:04:47 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int NMAX = 2000000;
bool v[NMAX + 1];
ifstream f("ciur.in");
ofstream g("ciur.out");
void ciur(int n)
{
int i, j;
v[0] = v[1] = 1;
for(i = 4; i <= n; i += 2)
v[i] = 1;
for(i = 3; i * i <= n; i += 2)
if(v[i] == 0)
for(j = i * i; j <= n; j += 2 * i)
v[j] = 1;
}
int main()
{
int n, c = 0;
ciur(NMAX);
f >> n;
while(n--)
{
if(v[n] == 0)
c++;
}
g << c;
f.close();
g.close();
return 0;
}
