Cod sursa(job #2917396)

Utilizator raresgherasaRares Gherasa raresgherasa Data 4 august 2022 18:56:50
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("ciur.in");
ofstream fout ("ciur.out");

const int NM = 2e6 + 5;

bitset<NM>c;

int main(){
  int n; fin >> n;
  for (int i = 4; i <= n; i += 2){
    c[i] = true;
  }
  for (int i = 3; i * i <= n; i += 2){
    if (c[i] == false){
      for (int j = i * i; j <= n; j += i){
        c[j] = true;
      }
    }
  }
  int ans = 0;
  for (int i = 2; i <= n; i++){
    ans += (c[i] == false);
  }
  fout << ans;
}