Cod sursa(job #3312703)

Utilizator depevladVlad Dumitru-Popescu depevlad Data 29 septembrie 2025 16:26:15
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>

using namespace std;

int main() {
#ifndef LOCAL
  freopen("ciur.in", "r", stdin);
  freopen("ciur.out", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<bool> P((N >> 1) + 1);
  for (int p = 1; ((p * p) << 1) + (p << 1) <= N; ++p) {
    if (!P[p]) {
      for (int q = ((p * p) << 1) + (p << 1); (q << 1) + 1 <= N;
           q += (p << 1) + 1) {
        P[q] = 1;
      }
    }
  }
  int M = 1;
  for (int i = 1; (i << 1) + 1 <= N; ++i) {
    if (!P[i]) {
      ++M;
    }
  }
  cout << M << "\n";
  return 0;
}