Cod sursa(job #2573536)
| Utilizator | Data | 5 martie 2020 18:04:19 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 30 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
long long n;
bool v[200000];
int main()
{
int n, nr = 0;
fin >> n;
for(int i = 1; i <= n; i++)
v[i] = true;
for(int i = 2; i <= (int)sqrt(n); i ++)
if(v[i])
for(int j = i * i; j <= n; j += i)
v[j] = false;
for(int i = 2; i <= n; i++)
if(v[i]) nr++;
fout << nr;
}
