Cod sursa(job #3139087)

Utilizator ItsComplicatedMihai Ian ItsComplicated Data 24 iunie 2023 20:04:13
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>

using namespace std;

int x, total, limit;
short v[2000002];

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

  fin >> x;
  for(int i = 2; i <= x; i++) {
    if (v[i] == 0) {
      total ++;
      for(int j = i + i; j <= x; j += i) {
        v[j] = 1;
      }
    }
  }

  fout << total << std::endl;

  fin.close();
  fout.close();
  return 0;
}