Cod sursa(job #2252086)

Utilizator AngelEclipseGarleanu Alexandru Stefan AngelEclipse Data 2 octombrie 2018 12:06:04
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda musai_must Marime 0.36 kb
#include <bits/stdc++.h>
using namespace std;

ifstream f("ciur.in");
ofstream g("ciur.out");

bool p[500001] = {0};

int ciur(int n) {
  int nr = 1;
  for (int i = 3; i <= n; i += 2) {
    if (p[i] == 0) {
      nr++;
      for (int j = i * 3; j <= n; j += i << 1) {
        p[j] = 1;
      }
    }
  }
  return nr;
}

int main() {
    int n;
    f>>n;
    g<<ciur(n);
}