Cod sursa(job #2143239)

Utilizator oso.andinoooIonut Stan oso.andinooo Data 25 februarie 2018 18:34:01
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <bits/stdc++.h>
using namespace std;

bool ciur[2000005];

int main() {
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);
    int n, ans = 0;
    scanf("%d", &n);
    for(int i = 2; i <= n; i++) {
        if(ciur[i] == 0) {
            ans++;
            for(int j = 2; i * j <= n; j++)
                ciur[i*j] = 1; } }
    printf("%d", ans);
    return 0; }