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<cstdio>
#include<cstring>

const int N = 19;
int dp[N];
int isprime[N];

int main()
{
    dp[1] = 0;
    for(int i=2;i<N;i++)
    {
        if(!isprime[i])
            for(int j=2*i;j<N;j+=i)
                isprime[j] = 1;
        dp[i] = dp[i-1] + ((isprime[i])?0:1);
    }

    int y;
    while(~scanf("%d",&y))
        printf("%d\n",dp[y]);
    return 0;
}

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

using namespace std;

bool is_prime(const unsigned n);


int main(){
	int n;

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

		for(int number=2;number<=n;number++){
			if(is_prime(number))ans++;
		}
		printf("%d\n",ans);
	}


	return 0;
}

bool is_prime(const unsigned n){
	if(n == 2)return true;

    if(n%2 == 0) return false;

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

    return true;
}

C++: 
#include<iostream>
#define N 1000000


using namespace std;
void PrimeNum(int n,bool Primeif[]){
  for(int i = 2;i*i <= n;i++){
    if(Primeif[i] == true){
      for(int k = 2;k * i <= n;k++){
	Primeif[k*i] = false;
}
    }
  }
}
int main(){
  int n,num;
  bool Primeif[N+1];
  Primeif[1] = false;
  for(int i = 2;i < N;i++){
    Primeif[i] = true;
  }
  PrimeNum(N+1,Primeif);
  
  while(cin >> n){
    num = 0;
    for(int i = 0;i < n;i++){
      if(Primeif[i] == true){
	num = num+1;
      }
    }
     cout << num << endl;
     
   } 
    
}

C++: #include <bits/stdc++.h>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

const int inf=100000000;

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int cnt=0;
    for(int i=1; i<=n; i++)
    {
        if(isprime(i)) ++cnt;
    }
    cout<<cnt<<endl;
}

C++: // IncludingFiles
#include<iostream>
#include<vector>
#include<cmath>
#include<ctime>

// Defines
#define     MAX_NUMBER     (999999)
#define     MIN_NUMBER     (1)
// #define     __DEBUG__

// Using Namespace
using namespace std;

// Function
int main(){
	vector <int> PrimeNumbers;
	vector <int> input;
	int buf;
	int sz,maxn;
	int i,root;

	// 入力
	while(cin >> buf){
#ifdef __DEBUG__
		// 入力値のチェック
		if((buf < ((int)(MIN_NUMBER))) || (buf > ((int)(MAX_NUMBER)))){
			cerr << "InputError!!" << endl;
			return -1;
		}
#endif
		// 入力値をリストに追加
		input.push_back(buf);
	}

	// n の最大値を求めて maxn に代入
	sz = (int)input.size();
	maxn = input[0];
	for(i=1;i<sz;i++){
		if(maxn < input[i]){
			maxn = input[i];
		}
	}

	// 素数2 を 素数表PrimeNumbers に追加
	PrimeNumbers.push_back(2);

	// 3 から maxn までの整数が素数かどうかを調べ、素数であれば 素数表PrimeNumbers に追加
	for(i=3;i<=maxn;i+=2){
		// root に i の平方根を代入
		root = (int)sqrt(i);
		// sz に 素数表PrimeNumbers の大きさを代入
		sz = (int)PrimeNumbers.size();
		// i が 素数表PrimeNumbers に含まれている素数で割り切れないかを確認
		for(buf=0;(buf < sz) && (PrimeNumbers[buf] <= root);buf++){
			if((i % PrimeNumbers[buf]) == 0){						// もし割り切れたら
				goto NotPrime;										// i を素数表に追加しない
			}
		}
		// i は素数である ならば i を 素数表PrimeNumbers に追加
		PrimeNumbers.push_back(i);
		// ここにジャンプする
		NotPrime:;
	}

	// n 以下の素数の個数を計測
	sz = (int)input.size();
	for(i=0;i<sz;i++){
		// a, b および flag の宣言・初期化
		int a = 0,b = (int)PrimeNumbers.size() - 1,m,n;
		bool flag = false;

		// PrimeNumbers の最大値 <= input[i] となっていないかどうかを調べる
		if(PrimeNumbers[b] <= input[i]){
			n = b;
			flag = true;
		}

		// 二分検索
		while (flag == false){
			m = (a + b) / 2;
			if(PrimeNumbers[m] > input[i]){
				b = m;
			}else if((PrimeNumbers[m] <= input[i]) && (PrimeNumbers[m+1] > input[i])){
				n = m;
				flag = true;
			}else if(PrimeNumbers[m] < input[i]){
				a = m;
#ifdef __DEBUG__
			}else{
				cerr << "BinarySearchError!!" << endl << endl;
				cerr << "PrimeNumbers[" << m << "] = " << PrimeNumbers[m] << endl;
				cerr << "PrimeNumbers[" << (m + 1) << "] = " << PrimeNumbers[m+1] << endl;
				cerr << "input[" << i << "] = " << input[i] << endl;
				return -1;
			}
#else
			}
#endif
		}

		// 出力
		cout << n << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		vector<int> prime;
		
		for (int i = 2; i <= n; i++){
			int j;
			for (j = 0; j < prime.size(); j++){
				if (i % prime[j] == 0){
					break;
				}
			}
			if (j == prime.size()){
				prime.push_back(i);
			}
		}
		printf("%d\n", prime.size());
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
static const int MAX = 999999;

bool isPrime[MAX + 1];
int numPrime[MAX + 1];

void calcPrime(){
  for(int i = 0; i <= MAX; i++)
    isPrime[i] = true;
  isPrime[0] = isPrime[1] = false;
  for(int i = 0; i * i <= MAX; i++){
    if(isPrime[i]){
      for(int j = i * 2; j <= MAX; j += i)
        isPrime[j] = false;
    }
  }
  int sum = 0;
  for(int i = 0; i <= MAX; i++){
    if(isPrime[i])
      sum++;
    numPrime[i] = sum;
  }
}

int main(){
  int n;
  calcPrime();
  while(cin >> n){
    cout << numPrime[n] << endl;
  }
}

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

int main() {
    const int numPrimes = 1000000;
	bool primes[numPrimes];
    for (int i = 0; i != numPrimes; ++i) {
        primes[i] = true;
    }

    for (int i = 2; i != sqrt(numPrimes); ++i) {
        for (int j = 2; i * j < numPrimes; ++j) {
            primes[i*j] = false;
        }
    }

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

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

int main()
{
    int n , m;
    int prime[1000000];
    while(1){
        cin >> n;
        prime[1]=2;
        m=3;
        int i=2;
        while(i<=n){
            int flag=0;
            for(int j=1 ; j<i ; j++){
                if(m % prime[j] == 0){
                    flag++;
                }
            }
            if(flag == 0){
                prime[i]=m;
                i++;
            }
            m++;
        }
        cout << prime[n] <<endl;
    }
	return 0;
}