Cod sursa(job #1699496)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 7 mai 2016 15:42:55
Problema Ciurul lui Eratosthenes Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include<fstream>
#include<vector>
using namespace std;
int n, i, j, nr;
int low[2000005], v[2000005];
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int main(){
    fin>> n;
    for(i = 2; i <= n; i++){
        if(low[i] == 0){
            v[++nr] = i;
            low[i] = i;
        }
        for(j = 1; j <= nr && i * v[j] && v[j] <= low[i]; j++){
            low[i * v[j] ] = v[j];
        }
    }
    fout<< nr <<"\n";
    return 0;
}