Cod sursa(job #2054697)

Utilizator KernelovicNegrean Victor Kernelovic Data 2 noiembrie 2017 13:32:38
Problema Ciurul lui Eratosthenes Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>

using namespace std;

//multiple = 1, prime = 0

bool sir[2000001];

int main()
{
    ifstream inf("ciur.in");
    ofstream outf("ciur.out");

    int n; inf >> n;
    int aux, s = 0;

    for(int i = 2; i <= n; i++)
    {
        aux = i;
        if(sir[i]) continue;

        for(int j = i * 2; j <= n; j *= 2)
        {
            aux *= aux;
            sir[aux] = true;
            sir[j] = true;
        }
    }

    for(int i = 2; i <= n; i++)
    {
        if(sir[i] == false)
        {
            s += 1;
        }
    }
    outf << s;
}