Cod sursa(job #2695531)

Utilizator MorarCezar12Morar Cezar MorarCezar12 Data 13 ianuarie 2021 16:14:04
Problema Ciurul lui Eratosthenes Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ciur.in");
ofstream fout("ciur.out");
bool c[1000005];
int main()
{
    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;
    int cnt=0;
    fin >> n;
    for(int i = 1; i <= n; ++i)
    {
        if(c[i] == 0)
            cnt++;
    }
    fout << cnt;
    return 0;
}