Cod sursa(job #2980436)
| Utilizator | Data | 16 februarie 2023 15:13:22 | |
|---|---|---|---|
| Problema | Ciurul lui Eratosthenes | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
#define MAX 2000000
using namespace std;
ifstream fin ("ciur.in");
ofstream fout ("ciur.out");
bitset <MAX + 5> ciur;
int n, ans = 1;
int main()
{
fin >> n;
ciur[0] = ciur[1] = 1;
for(int i = 4; i <= n; i += 2)
ciur[i] = 1;
for(int i = 3;i <= n; i += 2)
{
if(!ciur[i])
{
ans++;
for(int j = i + i + i;j <= n; j += i << 1)
ciur[j] = 1;
}
}
fout << ans;
}
