Cod sursa(job #2211494)

Utilizator PetyAlexandru Peticaru Pety Data 10 iunie 2018 17:20:49
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <bits/stdc++.h>

using namespace std;

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

int n, cnt;

bitset<2000002>b;

void ciur () {
  for (int i = 4; i <= n; i += 2)
    b[i] = 1;
  for (int i = 3; i * i <= n; i += 2)
    if (b[i] == 0)
      for (int j = i * i; j <= n; j += 2 * i)
        b[j] = 1;
}

int main()
{
  fin >> n;
  ciur();
  for (int i = 2; i <= n; i++)
    if (b[i] == 0)
      cnt++;
  fout << cnt;
  return 0;
}