Cod sursa(job #1513892)

Utilizator andreiblajdevAndrei Blaj andreiblajdev Data 30 octombrie 2015 10:24:43
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <fstream>

#define nmax 2000001

using namespace std;

ifstream fi("ciur.in");
ofstream fo("ciur.out");

int n, rez;
bool A[nmax];

void read();
void ciur();
void write();

int main()
{
    
    read();
    ciur();
    write();
    
    fi.close();
    fo.close();
    
    return 0;
}

void read()
{
    fi >> n;
}

void ciur()
{
    int i, j;
    
    for (i = 2; i <= n; i++)
        if (A[i] == 0)
        {
            rez++;
            for (j = 2 * i; j <= n; j += i)
                A[j] = 1;
        }
}

void write()
{
    fo << rez << "\n";
}