Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	a, _ := strconv.Atoi(scanner.Text())
	return a
}

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return true
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cmath>
#include <complex>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>
#include <valarray>
#include <list>

using namespace std;

typedef long long ll;

template<class T>
struct Pi {
    T x, y;
    Pi() {}
    Pi(T xx, T yy) {
        x = xx; y = yy;
    }
    bool operator<(const Pi &r) const {
        if (x != r.x) return x < r.x;
        return y < r.y;
    }
    bool operator>(const Pi &r) const {
        if (x != r.x) return x > r.x;
        return y > r.y;
    }
    bool operator==(const Pi &r) const {
        if (x != r.x) return false;
        return y == r.y;
    }
};

template<class T>
struct Ti {
    T x, y, z;
    Ti() {}
    Ti(T xx, T yy, T zz) {
        x = xx; y = yy; z = zz;
    }
    bool operator<(const Ti &r) const {
        if (x != r.x) return x < r.x;
        if (y != r.y) return y < r.y;
        return z < r.z;
    }
    bool operator>(const Ti &r) const {
        if (x != r.x) return x > r.x;
        if (y != r.y) return y > r.y;
        return z > r.z;
    }
    bool operator==(const Ti &r) const {
        if (x != r.x) return false;
        if (y != r.y) return false;
        return z == r.z;
    }
};

int main() {
    int n;
    cin >> n;
    int res = 0;
    for (int i = 2; i <= n; i++) {
        bool f = true;
        for (int j = 2; j*j <= i; j++) {
            if (!(i%j)) {
                f = false;
                break;
            }
        }
        if (f) {
            //printf("%d\n", i);
            res++;
        }
    }
    printf("%d\n", res);
    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++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <iomanip>
#include <sstream>

using namespace std;

#define ll long long
#define eps 1e-7
#define inf 0x1fffffff
#define maxn 1000010



bool is[maxn];
vector<int>p;



int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	int n;
	memset(is,true,sizeof(is));
	for(int i=2;i<maxn;i+=2)
		is[i] = false;
	is[0] = is[1] = false;
	p.push_back(2);
	for(int i=3;i<maxn;i+=2)
	{
		if(is[i])
		{
			p.push_back(i);
			for(int j=i+i;j<maxn;j+=i)
			{
				is[j] = false;
			}
		}
	}
	while(cin>>n)
	{
		cout<<upper_bound(p.begin(),p.end(),n)-p.begin()<<endl;
	}
	return 0;
}

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

int main() {
  constexpr int max = 1000000;
  vector<bool> isPrime(max, true);
  isPrime[0] = isPrime[1] = 0;
  for (int i = 2; i * i < max; i++) {
    if (isPrime[i]) {
      for (int j = 2; i * j < max; j++) {
        isPrime[i * j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n,visited,cnt=0;
  
  while(1){
    int count =0;
    cnt++;
    if(cnt==30)break;
    cin >> n;
    if(n==0)count =0;
    for(int j=2;j<=n;j++){
      visited=0;
      for(int i = 2;i<=n;i++){
	
	if(j%i==0&&j!=i)visited=1;
	else if(j%i==0&&j==i&&visited==0)count++;
	
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

#define Max 1000000
int Prime[Max] = {};

int main()
{
	//?????????
	for (int i = 2; i < Max; i++)
	{
		Prime[i] = 1;
	}
	//??¨??????????????????????????????
	for (int i = 2; i*i < Max; i++)
	{
		if (Prime[i] == 1)
		{
			for (int j = i * 2; j < Max; j += i)
			{
				Prime[j] = 0;
			}
		}
	}
	//?´???????????¨????
	for (int i = 2; i < Max; i++)
	{
		Prime[i] += Prime[i - 1];
	}

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

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while (1)
	{
		int tmp;

		cin >> tmp;

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		if (cin.eof()) { break; }
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int prime[1000000];
signed main(void) {
  REP(i, 1000000) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= 1000000; i++) {
  	if (prime[i]) {
  		for (int j = 2 * i; j <= 1000000; j += i) {
  			prime[j] = 0;
  		}
  	}
  }
  //REP(i, 10) cout << prime[i] << " "; cout << endl;
  FOR(i, 1, 1000000) {
    prime[i] += prime[i-1];
    //cout << prime[i] << endl;
  }
  int n;
  while (cin >> n) {
    cout << prime[n] << endl;
  }
  return 0;
}

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

bool primeFlg[1000000];

void makePrime(){
  memset(primeFlg, true, sizeof(primeFlg));
  primeFlg[0] = primeFlg[1] = false;

  for(int i = 2; i * i <= 1000000; i++){
    if(primeFlg[i]){
      for(int j = i + i; j < 1000000; j += i){
        primeFlg[j] = false;
      }
    }
  }
}

int main(){
  int n;

  makePrime();

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

    for(int i = 0; i <= n; i++){
      primeCount += primeFlg[i];
    }

    cout << primeCount << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    int n, N=1000000;
	bool p[1000000]={0};

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