Cod sursa(job #2055078)

Utilizator KernelovicNegrean Victor Kernelovic Data 2 noiembrie 2017 20:16:09
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 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 s = 0;
 
    for(int i = 2; i <= n; i++)
    {
        if(sir[i]) continue;
 
        for(int j = i * 2; j <= n; j += i)
        {
            sir[j] = true;
        }
    }
 
    for(int i = 2; i <= n; i++)
    {
        if(sir[i] == false)
        {
            s += 1;
        }
    }
    outf << s;
}