Cod sursa(job #2298845)

Utilizator RazvanDinuRazvan Dinu RazvanDinu Data 8 decembrie 2018 16:06:08
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in ("ciur.in");
ofstream out ("ciur.out");
bool v[2000005];
int main()
{
    int i, j, n, k=0;
    in>>n;
    for(i=2; i<=n; i++)
    {
        v[i]=1;
    }
    for(i=2; i<=n; i++)
    {
        if(v[i]==1)
        {
            k++;
            for(j=i+i; j<=n; j+=i)
            {
                v[j]=0;
            }
        }
    }
    out<<k;
    return 0;
}