Cod sursa(job #948102)

Utilizator rootsroots1 roots Data 9 mai 2013 14:54:06
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <stdio.h>
#include <iostream>
using namespace std;

#define MAXSIZE 2000001

char p[MAXSIZE];

int Primes_2(int n)
{
    int i, j, nr = 1;
    for (i = 3; i <= n; i += 2)
        if (p[i] == 0)
        {
            nr++;
            for (j = 3*i; j <= n; j += 2*i)
            p[j] = 1;
        }
    return nr;
}

int main()
{
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);

    int N;
    cin >> N;
    cout << Primes_2(N) << '\n';

    return 0;
}