Cod sursa(job #790826)

Utilizator mihaiSimuSimu Mihai mihaiSimu Data 22 septembrie 2012 14:17:05
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <stdio.h>
#include <bitset>
using namespace std;

bitset<2000006> b;

int main(){

	freopen("ciur.in","r",stdin);
	freopen("ciur.out","w",stdout);
	long n,nr=0;
	scanf("%ld",&n);
	
	b.reset();
	b.flip();
	b[0]=0;
	b[1]=1;
	for(int i=2;i<=n;i++){
		if(b[i]){
			nr++;
			for(long j=i*2;j<=n;j+=i){
				int ij=(int)j;
				b[ij]=0;
			}
		}
	}

	printf("%d\n",nr);
	return 0;
}