Cod sursa(job #2120071)

Utilizator Andrei.GheorgheAndrei Gheorghe Andrei.Gheorghe Data 1 februarie 2018 21:12:20
Problema Ciurul lui Eratosthenes Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.35 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");
bool a[2000003];
int nr;
int main()
{
    int n;
    in>>n;
    for(int i=2;i<=n;i++)
    {
        if(a[i]==0)
        {
            nr++;
            for(int j=i+i;j<=n;j=j+i)
                a[j]=1;
        }
    }
    out<<nr;
}