Cod sursa(job #1345347)

Utilizator KanghuAndre Popescu Kanghu Data 17 februarie 2015 15:54:46
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 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 = 1; a < x; a++)
    {
        if(!c[a])
        {
            for(int b = (a+1)*(a+1); b < x; b = b + (a+1))
            {
                c[b] = true;
                s++;
            }
        }
    }

    o << s;

    return 0;
}