Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int i=0;
  int j=0;
  int n=0;
  int a[1000000]={};
  int sum=0;

  while(scanf("%d",&n)!=EOF)
    {
      for(i=0;i<1000000;i++)
        a[i]=1;
      sum=0;

      for(i=2;i<=n;i++)
        {
          if(a[i-1]==0)
            continue;
          for(j=2;j<=n/i;j++)
            a[i*j-1]=0;
        }

      for(i=1;i<n;i++)
        sum+=a[i];

      cout<<sum<<endl;

    }


  return 0;

}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
bool isprime[1000000];
vector<lnt> primes;

int main()
{
	fill(isprime,isprime+1000000,1);
	isprime[0]=isprime[1]=0;
	for(lnt i=2;i<1000000;i++){
		if(!isprime[i]) continue;
		primes.push_back(i);
		for(lnt j=2*i;j<1000000;j+=i) isprime[j]=0;
	}
	lnt n;
	while(scanf("%lld",&n)!=EOF){
		cout<<upper_bound(primes.begin(),primes.end(),n)-primes.begin()<<endl;
	}
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 1;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 1;
	for (int i = 1;i<=num;i++) {
		
		for (int j=2;j<i;j++) {
			if (i%j==0) {
				count ++;
				break;
			}
			
		}
	}
	cout << (num-count) <<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
 
int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

	for(int i=3; i*i<=n; i+=2){
		if(n%i==0){
			return 0;
		}
	}
	return 1;

}

//0009
int main()
{
	int n;
 
	while(cin >> n){
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}

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

bool prime_number(int n);
int proceed;
bool pn[1000000];

int main(int argc, char** argv) {
	int n, i, result;

	while(std::cin >> n) {
		if(n < 2) {
			result = 0;
		}else {
			result = 1;
			for(i = 3; i <= n; i += 2) {
				if(prime_number(i)) {
					result++;
				}
			}
		}
		std::cout << result << std::endl;
	}
}

bool prime_number(int n) {
	if(n <= proceed){
		return pn[n];
	}
	proceed = n;
	int i;
	double rt = sqrt(n);
	if(n < 2) {
		return false;
	}else if(n == 2) {
		pn[2] = true;
		return true;
	}else if(n % 2 == 0) {
		return false;
	}
	for(i = 3; i <= rt; i += 2) {
		if(n % i == 0) {
			return false;
		}
	}
	pn[n] = true;
	return true;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;

int prime[1000000];
bool is_prime[1000000];
int seive(int n){
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i){
				is_prime[j]=false;
			}
		}
	}
	return p;
}
//??¨????????????????????????
int main() {
	int n;
	while(cin>>n){
		cout<<seive(n)<<endl;
	}
}

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

int prime[1000000] = {1};

int main()
{
  int n;
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 1000000; i++){
    if (prime[i] == 1){
      for (int j = 2 * i; i < 1000000; j += i){
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 1000000; i++){
    prime[i + i] += prime[i];
  }
  while (cin >> n){
    cout << prime[n];
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>
#include <iomanip>

int main();
int count_prime_number(int n);

int main(){
	int input;
	std::vector<int> answer;
	
	
	//for (int i = 0; i < 3; i++){
		//std::cin >> input;
	while (std::cin >> input){
		answer.push_back(count_prime_number(input));
	}

	for (int i = 0; i < answer.size(); i++){
		std::cout << answer[i] << std::endl;
	}

	//while (1);
	return 0;
}

/**
* nまでの素数の個数を出力する
* args:数値n
* return:素数の個数
* 参考:http://tsg.ne.jp/TT/tsg/c/mansaku/P01.html
*/
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i += 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j += 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

C++: /*
*AOJ0009: Prime Number
**問題
[http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp:title]
**解法
エラトステネスのふるい。
*/
#include <fstream>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
const int N = 1000000;

int main() {
  // エラトステネスのふるいを作成
  bool isPrime[N]; // ふるい
  int cntPrime[N]; // n個以下の素数の個数
  for (int i = 0; i < N; i++)
    isPrime[i] = true;
  isPrime[0] = false; isPrime[1] = false;
  cntPrime[0] = 0;
  for (int i = 1; i < N; i++) {
    if (isPrime[i]) {
      cntPrime[i] = cntPrime[i-1] + 1;
      for (int j = 2 * i; j < N; j += i)
        isPrime[j] = false;
    } else {
      cntPrime[i] = cntPrime[i - 1];
    }
  }

  // 入力と出力
  int n;
  while (cin >> n) {
    cout << cntPrime[n] << endl;
  }

}

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

int main(void)
{
  int prm[1000000];
  for (int i = 0; i < 1000000; i++) prm[i] = 1;
  prm[0] = prm[1] = 0;
  for (int i = 2; i < 1000000; i++) {
    for (int j = 2; i*j < 1000000; j++) {
      prm[i*j] = 0;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    while (n) {
      if (prm[n]) ans++;
      n--;
    }
    cout << ans << endl;
  }

  return 0;
}

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

int main() {
	int n, count;
	bool *data;

	while (cin >> n) {
		data = new bool[n+1];
		count = 0;
		data[0] = data[1] = false;
		for (int i = 2;i <= n;i++) {
			if (data[i]) {
				count++;
				for (int j = i + i;j <= n;j += i) {
					data[j] = false;
				}
			}
		}
		cout << count << endl;
		delete[] data;
	}
	return 0;
}

C++: #include <cstdio>
#include <cmath>

using namespace std;

int main()
{
    int n;

    while(scanf("%d",&n)!=EOF){
        int sieve[n];
        for(int i=0;i<n;i++) sieve[i]=0;
        sieve[0]=sieve[1]=1;

        int lim=(int)sqrt(n);
    
        for(int i=2;i<=lim;i++){
            if(sieve[i]==0){
                int p=i;
                for(int j=(i+1);j<n;j++){
                    if(j%p==0) sieve[j]=1;
                }
            }
        }

        int cnt=0;
        for(int i=2;i<=n;i++){
            if(sieve[i]==0) cnt++;
        }

        printf("%d\n",cnt);
    }

    return 0;
}