Cod sursa(job #751033)

Utilizator test1Trying Here test1 Data 23 mai 2012 23:08:42
Problema Ciurul lui Eratosthenes Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define TEST 0

void open_file(){
    if(TEST)
    {
        freopen("test.in","r",stdin);
        freopen("test.out","w",stdout);
    } else
    {
        freopen("ciur.in","r",stdin);
        freopen("ciur.out","w",stdout);
    }
}

int n,nr;
bool p[1000111];

void ciur(){
    int i=2;
    while(i<=1000)
    {
        while(p[i])i++;
        for(int j=i*i;j<=1000000;j+=i)p[j]=1;
        i++;
    }
}

int main(){

    open_file();

    ciur();

    scanf("%d",&n);

    for(int i=2;i<=n;i++)
    if(!p[i])nr++;

    printf("%d\n",nr);

    return 0;
}