Cod sursa(job #2443238)
Utilizator | Surani Adrian Therevengerking | Data | 27 iulie 2019 00:31:27 |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
const int Nmax = 2000000 + 5;
bool v[Nmax];
int n, cnt;
int main()
{
fin >> n;
for(int i = 2; i * i<= n; ++i)
if(!v[i])
{
for(int j = i + i; j <= n; j += i)
v[j] = 1;
}
for(int i = 2; i <= n; ++i)if(!v[i])++cnt;
fout << cnt;
return 0;
}