Cod sursa(job #2572588)

Utilizator saladariusSala Darius saladarius Data 5 martie 2020 13:28:06
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include<fstream>
#define M 2000005
using namespace std;
 unsigned short int prim[M];
int main ()
{
    fstream f("ciur.in",ios::in), g("ciur.out",ios::out);
    unsigned long int N;
    unsigned short int nr,i,j;
    f>>N;
    nr=1;
    for (i=3;i<=N;i+=2)
    {
        if (!prim[i])
        {
            ++nr;
            if (i*i<=N)
            for (j=2*i;j<=N;j+=i)
                prim[j]=1;
        }
    }
    g<<nr;
    return 0;
}