Cod sursa(job #2031860)

Utilizator giotoPopescu Ioan gioto Data 3 octombrie 2017 21:59:05
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <bits/stdc++.h>
using namespace std;

int n;
bitset <2000005> p;
int main()
{
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);
    scanf("%d", &n);
    int NR = 1;
    for(int i = 1; ((i * i) << 1) + (i << 1) <= n ; i += 1){
        if(p[i] == 0){
            int x = (i << 1) + 1;
            for(int j = ((i * i) << 1) + (i << 1) ; (j << 1) + 1 <= n ; j += x)
                p[j] = 1;
        }
    }
    for(int i = 1; 2 * i + 1 <= n ; ++i)
        if(p[i] == 0) ++NR;
    printf("%d", NR);
    return 0;
}