Cod sursa(job #2552674)
Utilizator | Data | 21 februarie 2020 09:19:46 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <bits/stdc++.h>
using namespace std;
int n, nmax = 2000001;
vector<bool> a(nmax);
int main(){
ifstream cin("ciur.in");
ofstream cout("ciur.out");
cin >> n;
for(int i = 2; i * i <= nmax; ++i)
if(!a[i])
for(int j = 2; j <= nmax / i; ++j)
a[i * j] = 1;
int ans = 0;
for(int i = 2; i <= n; ++i)
if(!a[i])
++ans;
cout << ans;
}