Cod sursa(job #3204188)

Utilizator tudorhorotanHorotan Tudor tudorhorotan Data 15 februarie 2024 21:17:21
Problema Ciurul lui Eratosthenes Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int v[2000001];

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


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