Cod sursa(job #2170699)

Utilizator AndreiOffCovaci Andrei-Ion AndreiOff Data 15 martie 2018 09:27:14
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>
#include <vector>
#define NMAX 2000020
using namespace std;

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

bool a[NMAX];

int nr, n;

int main()
{

f>>n;

for(int i=2; i*i<=NMAX-20; i++){

    if(a[i]==0){
        for(int j=i*i; j<=NMAX-20; j+=i)
            a[j]=1;

    }

}
for(int i=2; i<=n; i++)
    if(a[i]==0) nr++;
g<<nr;
    return 0;
}