Cod sursa(job #1899454)

Utilizator kywyPApescu tiGEriu kywy Data 2 martie 2017 19:12:47
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include<cstdio>
using namespace std;
FILE* in = fopen("ciur.in", "r");
FILE* out = fopen("ciur.out", "w");
bool v[2000007];
int main()
{
    int n, ct = 0;
    fscanf(in, "%d", &n);
    for(int j = 2; j <= n; ++j)
    {
        if(v[j] == 0)
        {
            ++ct;
            if(1LL * j * j <= n)
            {
                for(int i = j * j; i <= n; i += j) v[i] = 1;
            }
        }
    }
    fprintf(out, "%d", ct);
}