Cod sursa(job #1751719)

Utilizator AhileGigel Frone Ahile Data 1 septembrie 2016 20:29:32
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include<bits/stdc++.h>
#define in f
#define out g
using namespace std;

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

int n;
int v[2000000];
int coun;


int main() {

    in >> n;
    for(int i = 2; i <= n; i++) {
        v[i] = i;
    }

    for(int i = 2; i <= n; i++) {
        if(v[i] != 0) {
            coun++;
            for(int j = 1; i * j <= n ; j++) {
                v[i*j] = 0;
            }
        }
    }
    out << coun;
    return 0;
}