Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: /*Filename: aoj0009.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

const int size = 999999 + 1;
bool isPrime[size];
vector<int> prime;

void sieveOfEratosthenes() {
	for (int i = 2; i < size; ++i) {
		isPrime[i] = true;
	}

	int sqrtSize = sqrt(size) + 1;

	for (int i = 2; i < sqrtSize; ++i) {
		if (isPrime[i] == true) {
			for (int j = i * i; j < size; j += i) {
				isPrime[j] = false;
			}
		}
	}

	for (int i = 2; i < size; ++i) {
		if (isPrime[i]) {
			prime.push_back(i);
		}
	}
}

int main() {
	sieveOfEratosthenes();

	int n = 0;

	while (cin >> n) {
		int countPrime = 0;

		for(int i = 0; i < prime.size(); ++i){
			if(prime[i] > n){
				break;
			}
			else{
				++countPrime;
			}
		}

		cout << countPrime << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int pri[1000000];
int main()
{
    int i,j;
    memset(pri,0,1000000*sizeof(int));
    for (i=2;i<=1000;i++)
    {
        for (j=i*i;j<1000000;j=j+i)
        {
            pri[j]=1;
        }
    }
    int n;
    while (scanf("%d",&n)!=EOF)
    {
        int sum=0;
        for (i=2;i<=n;i++)
            if (pri[i]==0) sum++;
        printf("%d\n",sum);
    }
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

vector<bool> eratosthenes_sieve(size_t size) {
  vector<bool> is_prime(size + 1, true);
  for (size_t i = 0; i <= size; i++) {
    if (i < 2) {
      is_prime[i] = false;
    } else if (is_prime[i]) {
      for (size_t j = 2 * i; j <= size; j += i) {
        is_prime[j] = false;
      }
    }
  }
  return is_prime;
}

int main() {
  int n = 1'000'000 - 1;
  auto sieve = eratosthenes_sieve(n);
  vector<int> acc(n + 1, 0);
  rep(i, n) { acc[i + 1] = acc[i] + (sieve[i + 1] ? 1 : 0); }

  int m;
  while (cin >> m) {
    cout << acc[m] << "\n";
  }
  return 0;
}

C++: #include <iostream>
#define NUM 1000000
using namespace std;

int Prime[NUM];

int main(){

	for( int i=0;i<NUM;i++ ){
		Prime[i]=1;
	}
	Prime[0]=Prime[1]=0;
	for( int i=2;i<NUM;i++ ){
		if( Prime[i] ){
			for( int j=i*2;j<NUM;j+=i ){
				Prime[j]=0;
			}
		}
	}
	int n;
	while( cin>>n ){
		int primenum=0;
		for( int i=0;i<=n;i++ ){
			primenum+=Prime[i];
		}
		cout<<primenum<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;


vector<int> era(int n){
	vector<int> prime;
	bool *is_prime = new bool[n+1];
	fill(is_prime,is_prime+n+1,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j = i*2; j <= n; j+=i){
				is_prime[j] = false;
			}
		}
	}
	delete []is_prime;
	return prime;
}

int main(){

	int n;
	while(1){
		if(cin.eof())
			break;
		cin >> n;
		vector<int> p = era(n);
		cout << p.size() << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <math.h>
using namespace std;

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

C++: /*
 * hujx.cpp
 *
 *  Created on: 2015年5月21日
 *      Author: dell
 */
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<time.h>
#include<queue>
#include<stack>
#include<iterator>
#include<math.h>
#include<stdlib.h>
#include<limits.h>
#include<map>
#include<set>
#include<bitset>
//#define ONLINE_JUDGE
#define eps 1e-5
#define INF 0x7fffffff
#define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define sfs(a) scanf("%s",a)
#define sf(a) scanf("%d",&a)
#define sfI(a) scanf("%I64d",&a)
#define pf(a) printf("%d\n",a)
#define pfI(a) printf("%I64d\n",a)
#define pfs(a) printf("%s\n",a)
#define sfd(a,b) scanf("%d%d",&a,&b)
#define sft(a,b,num) scanf("%d%d%d",&a,&b,&num)
#define for1(i,a,b) for(int i=(a);i<b;i++)
#define for2(i,a,b) for(int i=(a);i<=b;i++)
#define for3(i,a,b)for(int i=(b);i>=a;i--)
#define MEM1(a) memset(a,0,sizeof(a))
#define MEM2(a) memset(a,-1,sizeof(a))
#define ll long long
const double PI=acos(-1.0);
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
using namespace std;
//#pragma comment(linker,"/STACK:1024000000,1024000000")
int n,m,c;
#define N 210
#define M 1000100
#define Mod 1000000000
#define p(x,y) make_pair(x,y)
const int MAX_len=550;
int f[M],prime[M];
int vis[M];
int tot;
void get_Prime(){
	memset(f,0,sizeof f);
	tot=0;
	int p = (int)sqrt(M)+1;
	for(int i=2;i<p;i++){
		if(f[i]) continue;
		for(int j=i;i*j<M;j++)
			f[i*j] = 1;
	}
	for(int i=2;i<M;i++){
		f[i] ^= 1;
		f[i] += f[i-1];
	}
}
int main(){
    get_Prime();
    while(sf(n)!=EOF){
    	pf(f[n]);
    }
    return 0;
}

C++: #include <iostream>
#include <math.h>

using namespace std;

int main() {
  int N = 1000001;
  int primes[N];
  int i, j;
  for (i = 2; i < N; i++) {
    primes[i] = 1;
  }

  for (i = 2; i <= int(sqrt(N)); i++) {
    if (primes[i]) {
      for (j = i*i; j < N; j+=i) {
        primes[j] = 0;
      }
    }
  }

  int n;
  while (cin >> n) {
    int ans = 0;
    for (i = 2; i <= n; i++) {
      ans += primes[i];
    }
    cout << ans << endl;
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

int sang(long long  n,bool *s,long long  *p,long long &m){
	m = 0;
	for(long i = 2; i<=n;i++){
		s[i] = 2;
	}
	for(long i = 2; i<=n; i++){
		if(s[i]){
			p[m++] = i;
			for(long j = i * i; j<= n ; j += i){
				s[j] = 0;
			}
		}
	}
	return m;
}
int main(){
	bool s[100005];
	long long  n,p[100005],m;

	while(cin>>n){
		sang(n,s,p,m);
		cout<<m<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define m 1000000
using namespace std;

bool ba[m] = { true };
int cp(int x) {
	if (x < 2)return 0;
	if (x == 2)return 1;

	int co = 0;
	for (int i = 0; i < m; i++) {
		ba[i] = { true };
	}
	for (int i = 2; i*i <= x; i++) {
		if (ba[i]) {
			for (int j = i*i; j <= x; j += i) {
				ba[j] = { false };
			}
		}
	}
	for (int i = 2; i <= x; i++) {
		if (ba[i]) {
			++co;
		}
	}
	return co;
}

int main() {
	int x;
	while (cin >> x) {
		cout << cp(x) << endl;
	}
	return 0;
}