Cod sursa(job #2573541)

Utilizator sckoppeSiladi Ciprian sckoppe Data 5 martie 2020 18:05:10
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

ifstream fin("ciur.in");
ofstream fout("ciur.out");

long long n;
bool v[2000000];

int main()
{
    int n, nr = 0;
    fin >> n;

    for(int i = 1; i <= n; i++)
        v[i] = true;

    for(int i = 2; i <= (int)sqrt(n); i ++)
        if(v[i])
            for(int j = i * i; j <= n; j += i)
                v[j] = false;
    for(int i = 2; i <= n; i++)
        if(v[i]) nr++;

    fout << nr;

}