Mai intai trebuie sa te autentifici.
Cod sursa(job #2575851)
Utilizator | Data | 6 martie 2020 15:50:17 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
const int len = 2000005;
int n, cnt;
bool prime[len];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
cin >> n;
for (int i = 2; i <= n; i++)
prime[i] = true;
for (int i = 2; i <= n; i++)
if (prime[i]) {
cnt++;
for (int j = i; j <= n; j += i)
prime[j] = false;
}
cout << cnt;
}