Cod sursa(job #1276224)

Utilizator mariusbsUnibuc Serban mariusbs Data 26 noiembrie 2014 02:23:23
Problema Ciurul lui Eratosthenes Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.33 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("ciur.in");
ofstream out("ciur.out");

int main(){
	
bool *v;
v=new bool[2000001];

int n,i,d,cnt=0;
in>>n;
if(n>=2)
	cnt++;
for(i=3;i<=n;i+=2)
	if(v[i]==0){
		cnt++;
		for(d=i*i;d<=n;d+=i)
			v[d]=1;
	}
out<<cnt;

delete[] v;

return 0;	
}