Cod sursa(job #2662911)

Utilizator popashtefan10Popa Stefan popashtefan10 Data 24 octombrie 2020 20:18:07
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <cstdio>

using namespace std;

const int NMAX = 2000000;
const int BASE = 64;

long long ciur[NMAX / (2 * BASE) + 1];

int main() {
  freopen("ciur.in", "r", stdin);
  freopen("ciur.out", "w", stdout);
  int n, ans = 1;

  scanf("%d", &n);

  for(int i = 3; i <= n; i += 2)
    if(!( ciur[i / (2 * BASE)] & ((long long)1 << ((i / 2) % BASE)) )) {
      ans++;
      for(int j = 3 * i; j <= n; j += 2 * i)
        ciur[j / (2 * BASE)] |= ((long long)1 << ((j / 2) % BASE));
    }
  printf("%d", ans);

  return 0;
}