Cod sursa(job #2058181)

Utilizator hhhhhhhAndrei Boaca hhhhhhh Data 5 noiembrie 2017 11:31:59
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <fstream>

using namespace std;
int d,j,n,nr=0;
bool c[1000000];
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int main()
{
    fin>>n;
    c[0]=true;
    c[1]=true;
    for(int d=2;d<=n;d++)
        if(c[d]==false)
        {
            for(j=2;j<=n/d;j++)
                c[j*d]=true;
        }
    for(j=1;j<=n;j++)
        if(c[j]==false)
            nr++;
    fout<<nr;
    return 0;
}