Cod sursa(job #2088758)

Utilizator kodama cheama alex koda Data 15 decembrie 2017 20:11:15
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>

using namespace std;

bool c[2000000];

int main () {
  ifstream fin ("ciur.in");
  ofstream fout ("ciur.out");
  int p, w, n, i, s;
  c[0] = c[1] = 1;
  p = w = 2;
  fin>>n;
  while ( p * p <= n ) {
    w = p*2;
    while ( w <= n ) {
      c[w] = 1;
      w += p;
    }
    do p++;
    while ( c[p] && p <= n );
  }
  s = 0;
  for ( i = 0; i <= n; i++ )
    s += (c[i]+1)%2;
  fout<<s;
  return 0;
}