Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include <iostream>
#include <algorithm>
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 <= sqrt(n * 1.0); 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++: #include <bits/stdc++.h>
#define MAX_N 1000000
using namespace std;
bool prime[MAX_N];
int table[MAX_N];

void initialize() {
    int p = 0;
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false;
    for(int r = 2; r * r <= MAX_N; r++) {
        if(prime[r]) {
            table[p++] = r;
            for(int c = r * 2; c <= MAX_N; c+= r) {
                prime[c] = false;
            }
        }
    }
}


int main(void) {
    initialize();
    int num;
    while(cin >> num) {
        int cnt = 0;
        for(int r = 0; table[r] <= num; r++) cnt++;
        cout << cnt << endl;
    }
    return(0);
}

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

int main(){
	const int max_num=1000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

C++: #include <cstdio>
#include<cmath>
using namespace std;
int n,sum,c,flag;
int a[1000000] = {0};
int main()
{
	c = 1000000;
	for(;c > 0;c--){
		flag = 0;
		for(int i = 2;i <= sqrt(c);i++){
			if(c % i == 0)
				flag = 1;
		}
		if(flag == 0)
			a[c] = c;
	}
	while(scanf("%d",&n) != EOF){
		sum = 0;
		for(int j = n;j > 1;j--){
			if(a[j] != 0)
				sum++;
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

#define MAXINT 1000000
bool isprime[MAXINT];
ll int sum[MAXINT];
void makeprime(){
	REP(i,MAXINT) isprime[i] = true;
	FOR(i,2,sqrt(MAXINT)+1){
		FOR(j,i+1,MAXINT-1){
			if(j%i==0) isprime[j] = false;
		}
	}
}

int main(){
	makeprime();
	sum[0] = 0;
	sum[1] = 0;
	sum[2] = 1;
	/*FOR(i,3,MAXINT){
		if(isprime[i]) sum[i] = sum[i-1]+1;
		else sum[i] = sum[i-1];
	}*/
	ll int n;
	while(cin >> n){
		ll int ans = 0;
		REP(i,n) if(isprime[i]) ans++;
		cout << ans << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <assert.h>

/**
* @brief 可変長配列
*/
class Integers : public std::vector<int>
{
public:
    /**
    * @fn void add(int n)
    * @brief 要素を追加する
    * @param[in] val 追加対象
    */
    void add(int val)
    {
        this->push_back(val);
    }

    /**
    * @fn int indexOf(int idx)
    * @brief 指定した要素の値を取得する
    * @param[in] idx 指定する要素
    * @return int 要素の値
    */
    int indexOf(int idx)
    {
        assert(0 <= idx && getLength() - 1 >= idx);

        return static_cast<int&>(this->at(idx));
    }

    /**
    * @fn int getLength()
    * @brief 配列の長さを取得する
    * @return int 長さ
    */
    int getLength()
    {
        return this->size();
    }
};

class PrimeNumber
{
public:
    /**
    * @fn int getPrimeNumber(int data)
    * @brief dataまでの素数の個数を取得する
    * @param[in] data 入力データ
    * @return int 素数の数
    */
    int getPrimeNumber(int data);
};

class Control
{
public:
    /**
    * @fn bool executeEx()
    * @brief 入力の最後まで整数nを読み込み、n以下の素数の数を出力する
    * @return bool 入力値が範囲内またはデータセットが30以下ならtrueを、そうでなければfalseを返す
    */
    bool executeEx();

private:
    /**
    * @fn bool check(Integers& target)
    * @brief 入力範囲内かチェックする
    * @param[in] target チェック対象
    * @return bool 入力範囲内ならtrueを、そうでなければfalseを返す
    */
    bool check(Integers& target);

    /**
    * @fn void read(Integers& target)
    * @brief 入力終了まで読み込む
    * @param[out] target 入力データ
    */
    void read(Integers& target);

    /**
    * @fn void write(Integers& target)
    * @brief 素数の個数を出力する
    * @param[in] target 出力対象
    */
    void write(Integers& target);
};

//------------------------------------------------------

int PrimeNumber::getPrimeNumber(int data)
{
    int cnt = 0;

    if (1 == data)
        return 0;

    if (2 == data)
        return 1;

    if (3 == data)
        return 2;

    for (int i = 5; i <= data; i += 2) {
        if (0 == i % 3)
            continue;
        if (0 == i % 5)
            continue;
        if (0 == i % 7)
            continue;

        int square = (int)std::sqrt(i);
        bool isNotPrime = false;
        for (int j = 3; j <= square; j += 2) {
            if (0 == i % j) {
                isNotPrime = true;
                break;
            }
        }
        if (!isNotPrime) {
            cnt++;
        }
    }
    return cnt + 2;

}

bool Control::executeEx()
{
    static const int DataMax = 30;

    Integers input;
    Integers output;

    read(input);

    if (DataMax < input.getLength() || !check(input))
        return false;

    for (int i = 0; i < input.getLength(); i++) {
        output.add(PrimeNumber().getPrimeNumber(input.indexOf(i)));
    }

    write(output);

    return true;
}

bool Control::check(Integers& target)
{
    static const int Min = 1;
    static const int Max = 999999;

    for (int i = 0; i < target.getLength(); i++) {
        if (Min > target.indexOf(i) || Max < target.indexOf(i))
            return false;
    }

    return true;
}

void Control::read(Integers& target)
{
    int input = 0;

    while (std::cin >> input)
        target.add(input);
}

void Control::write(Integers& target)
{
    for (int i = 0; i < target.getLength(); i++) {
        std::cout << target.indexOf(i) << std::endl;
    }
}

/**
* @fn int main()
* @brief エントリポイント
*/
int main()
{
    if (!Control().executeEx())
        return 1;

}