Cod sursa(job #2975760)
Utilizator | Data | 7 februarie 2023 13:45:06 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <bits/stdc++.h>
#define MAXN 2000005
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
bitset<MAXN> dp;
void generation() {
dp[0] = dp[1] = 1;
for (int i = 4; i < MAXN; i += 2)
dp[i] = 1;
for (int i = 3; i * i < MAXN; i += 2)
if (!dp[i])
for (int j = i * i; j < MAXN; j += 2 * i)
dp[j] = 1;
}
int main() {
generation();
int n, count = 0;
fin >> n;
for (int i = 2; i <= n; i++)
if (!dp[i])
count++;
fout << count;
return 0;
}