Cod sursa(job #2963250)
| Utilizator | Data | 10 ianuarie 2023 17:06:33 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("ciur.in");
ofstream g ("ciur.out");
int prim[2000005] , i , n , cnt = 0;
int main()
{
prim[1] = 1;
for (int i = 2 ; i <= 2000000 ; i++)
{
if (prim[i] == 0)
{
for (int j = 2 * i ; j <= 2000000 ; j = j + i)
prim[j] = 1;
}
}
f >> n;
for (int i = 1 ; i <= n; i++)
if (prim[i] == 0)
cnt++;
g << cnt;
return 0;
}
