Cod sursa(job #1446186)

Utilizator daniel.grosuDaniel Grosu daniel.grosu Data 31 mai 2015 23:17:13
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.36 kb
#define REP(a,b) for(int a=0; a<(b); ++a)
#define FWD(a,b,c) for(int a=(b); a<(c); ++a)
#define FWDS(a,b,c,d) for(int a=(b); a<(c); a+=d)
#define BCK(a,b,c) for(int a=(b); a>(c); --a)
#define ALL(a) (a).begin(), (a).end()
#define SIZE(a) ((int)(a).size())
#define VAR(x) #x ": " << x << " "
#define FILL(x,y) memset(x,y,sizeof(x))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define x first
#define y second
#define st first
#define nd second
#define pb push_back
#define nleft (n<<1)
#define nright (nleft+1)

#include<vector>

using namespace std;
#include<fstream>
ifstream fin("ciur.in");
ofstream fout("ciur.out");

#define NMAX 2000005

const int INF = 0x3f3f3f3f;
const int dx[] = {0,0,-1,1}; //1,1,-1,1};
const int dy[] = {-1,1,0,0}; //1,-1,1,-1};

typedef long long LL;
typedef pair<int, int> PII;
typedef long double K;
typedef pair<K, K> PKK;
typedef vector<int> VI;

int n,m,i,j,s;

bool p[(NMAX>>1)+1];

int main()
{
	fin>>n;
	/* version I
	FWD(i,2,n+1)
		if(!p[i]){
			FWDS(j,i+i,n+1,i)
				p[j]=true;
			s++;
		}
	*/
	/* version II
	s=1;
	FWDS(i,3,n+1,2)
	{
		if(!p[i]){
			FWDS(j,3*i,n+1,i*2)
				p[j]++;
			s++;
		}
	}
	*/
	s=1;
	for(i=1; 2*i+1<=n; i+=1)
		if(!p[i])
		{
			for(j=3*i+1; 2*j+1<=n; j+=2*i+1)
				p[j]=1;
			s++;
		}
	fout<<s;
	return 0;
}