Cod sursa(job #2258316)

Utilizator ImbuzanRaduImbuzan Radu ImbuzanRadu Data 11 octombrie 2018 11:01:34
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <vector>
#include <cstdint>
#include <fstream>

using namespace std;

ifstream f ("ciur.in");
ofstream g ("ciur.out");

int main()
{
    int n;
    f>>n;
    int nr = n - 1;
    vector<uint8_t> ap(n + 1, 0);
    for(int i = 2; i <= n; i++)
    {
        if(ap.at(i) == 0)
        {
            for(int j = i; i * j <= n; j++)
            {
                if(ap.at(j * i) == 0)
                {
                    ap.at(j * i) = 1;
                    nr--;
                }
            }
        }
    }
    g<<nr;
    return 0;
}