Cod sursa(job #2723779)

Utilizator eddy_cimpanuCimpanu Eduardo Daniel eddy_cimpanu Data 15 martie 2021 16:18:20
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>
using namespace std;
bool c[1000005];
int main()
{
    ifstream fin("eratostene.in");
    ofstream fout("eratostene.out");
    c[0] = c[1] = 1;
    for(int i = 2; i <= 1000; ++i)
        if(c[i] == 0)
            for(int j = 2; i * j <= 1000000; ++j)
                c[i * j] = 1;
    int n;
    fin >> n;
    int x;
    int cnt = 0;
    for(int i = 1; i <= n; ++i){
        if(c[i] == 0)
            cnt++;
    }
    fout << cnt;
    return 0;
}