Cod sursa(job #3285706)

Utilizator blidar_lucian1Adrian Popescu blidar_lucian1 Data 13 martie 2025 13:28:36
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <bits/stdc++.h>

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

int n;
bool c[2000001];
void ciur() {
  c[0] = c[1] = 1;
  for(int i = 2; i <= 2000000; ++i) {
        if(c[i] == 0) {
    for(int j =2 * i; j <= 2000000; j += i)
        c[j] = 1;
        }
  }
}
int main()
{
    f >> n;
    ciur();
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        if(c[i] == 0) {
            if(i <= n ){
                cnt++;
            }
        }
    }
    g << cnt;
}