Cod sursa(job #1244690)

Utilizator js3292618Andrei Mihai js3292618 Data 17 octombrie 2014 23:35:19
Problema Ciurul lui Eratosthenes Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 0.53 kb
#include <stdio.h>

#define IN "ciur.in"
#define OUT "ciur.out"
#define NMAX 2000001

typedef unsigned long Int;

static char c[NMAX];

static Int ciur(Int n)
{
    Int i, j, cnt = 0;

    for (i = 2; i * i <= n; i++)
        if (!c[i])
            for (j = i * i; j <= n; j += i)
                c[j] = 1;

    for (i = 2; i <= n; i++)
        cnt += 1 - c[i];

    return cnt;
}

int main(void)
{
    Int n;

    freopen(IN, "r", stdin);
    freopen(OUT, "w", stdout);

    scanf("%lu", &n);
    printf("%lu\n", ciur(n));

    return 0;
}