Cod sursa(job #1345355)

Utilizator KanghuAndre Popescu Kanghu Data 17 februarie 2015 15:58:15
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <iostream>
#include <fstream>

using namespace std;

bool c[2000000];

int main()
{
    ifstream i("ciur.in");
    ofstream o("ciur.out");

    int x, s = 0;
    i >> x;

    for(int a = 2; a < x; a++)
    {
        if(!c[a])
        {
            for(int b = a*a; b < x; b = b + a)
            {
                c[b] = true;
                s++;
            }
        }
    }

    o << s;

    return 0;
}