Cod sursa(job #2644181)

Utilizator kodama cheama alex koda Data 23 august 2020 18:23:43
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;

bool v[2000001];

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

    fin>>n;

    for ( int starter = 2; starter * starter <= n; starter++ ) {
        marker = starter * 2;
        while ( marker <= n ) {
            v[marker] = true;
            marker += starter;
        }
        starter += starter % 2;
    }

    int t = 0;
    for ( int i = 2; i <= n; i++ )
        t += !v[i];

    fout<<t;

    return 0;
}