Cod sursa(job #2662901)

Utilizator popashtefan10Popa Stefan popashtefan10 Data 24 octombrie 2020 19:58:22
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <iostream>
#include <cstdio>

using namespace std;

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

long long ciur[NMAX / BASE + 1];

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

  scanf("%d", &n);

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

  return 0;
}