Cod sursa(job #2682161)

Utilizator andrei.florea0405Florea Andrei-Bogdan andrei.florea0405 Data 7 decembrie 2020 22:16:09
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

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

bool ciur[2000005];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    fin >> n;

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

    fout << count;
    
    return 0;
}