Cod sursa(job #2881225)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 30 martie 2022 12:50:00
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define dbg(x) cout << #x <<": " << x << "\n";
#define sz(x) ((int)x.size())

using ll = long long;

const string fn = "ciur";
ifstream fin(fn + ".in");
ofstream fout(fn + ".out");

int n;
 bitset<2000005> v;
int main(){

    fin >> n;
   
    for (int i = 4; i <= n; i += 2)
        v[i] = 1;
    for (int i = 3; i * i <= n; i += 2)
        if(!v[i])
            for (int j = i * i; j <= n; j += i + i)
                v[j] = 1;
    int nas = 0;
    for (int i = 2; i <= n; ++i)
        if(v[i] == 0)
            nas++;
    fout << nas << " ";
    return 0;
}