Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: #include<stdio.h>
#include<Math.h>

int main(){
	int n;
	int a[1000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

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

int n, sum[1000001], isP[1000001];
vector<int> p;

int main() {
  for (int i = 2; i * i <= 1000000; i++) {
    bool ok = true;
    for (int j = 0; j < p.size(); j++) if (i % p[j] == 0) {
      ok = false;
      break;
    }
    if (ok) p.push_back(i);
  }
  for (int i = 2; i <= 1000000; i++) isP[i] = 1;
  for (int i = 0; i < p.size(); i++) {
    int k = 2;
    while (p[i] * k <= 1000000) isP[p[i] * k] = 0, k++;
  }
  for (int i = 1; i <= 1000000; i++) sum[i] = sum[i-1] + isP[i];
  while (scanf("%d", &n), n) {
    printf("%d\n", sum[n]);
    n = 0;
  }
}

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

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

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
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 <vector>
using namespace std;

long long n;
vector<long long> p(1, 2);

int main()
{
	for (long long i = 3; i < 1000000; i += 2) {
		long long j = 0;
		bool f = 1;
		while(p[j] * p[j] <= i){
			if (i % p[j] == 0) {
				f = 0;
				break;
			}

			j++;
		}

		if (f)
			p.push_back(i);
	}

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

		while (m < p.size() && p[m] <= n)
			m++;

		cout << m << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
  
bool isprime(int n) {
    for(int i=2; i*i <= n; i++) {
        if(n%i==0) return false;
    }
    return n != 1;
}
  
int main() {
int n;
while(cin >> n) {
int cnt = 0;
for(int i=2; i<=n; i++) if(isprime(i)) cnt++;
cout << cnt << endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#include <map>

int main() {
	int a;
	while (std::cin >> a) {
		int nSum = 0;
		for (int i = 2;i <= a;i++) {
			int flag = 0;
		for (int j = 2;j < i;j++) {
			if (i%j == 0) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			nSum += 1;
		}
	}
		std::cout << nSum << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin>>n){
		int ans=0;
		std::vector<int> vec(n);
		for(int i=0;i<n;i++)vec[i]=1;
		vec[0]=vec[1]=0;
		for(int i=2;i<n;i++){
			if(vec[i] == 1){
				ans++;
				for(int j = 2 * i ; j < n ; j += i){
					vec[j]=0;
				}
			}
		}
		std::cout<<ans<<std::endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int x;
    int i, j;
    int p[999999] = {};
    p[2] = 1;
    for (i = 3; i < 1000000; i++) {
        for (j = 2; ; j++) {
            if (!(i % j)) {
                break;
            } else if (j > sqrt(i)) {
                p[i] = 1;
                break;
            }
        }
    }
    while (scanf("%d", &x) != EOF) {
        j = 0;
        for (i = 0; i <= x; i++) {
            j += p[i];   
        }
        printf("%d\n", j);
    }
    return 0;
}

C++: #include <bitset> // compact STL for Sieve, better than vector<bool>!
#include <vector>
#include <cstdio>
#include <iostream>
#define ll long long
#define vi vector<int>

using namespace std;

ll _sieve_size; // ll is defined as: typedef long long ll;
bitset<10000010> bs; // 10^7 should be enough for most cases
vi primes; // compact list of primes in form of vector<int>
void sieve(ll upperbound) { // create list of primes in [0..upperbound]
_sieve_size = upperbound + 1; // add 1 to include upperbound
bs.set(); // set all bits to 1
bs[0] = bs[1] = 0; // except index 0 and 1
for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
// cross out multiples of i starting from i * i!
for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i); // add this prime to the list of primes
} } // call this method in main method
bool isPrime(ll N) { // a good enough deterministic prime tester
if (N <= _sieve_size) return bs[N]; // O(1) for small primes
for (int i = 0; i < (int)primes.size(); i++)
if (N % primes[i] == 0) return false;
return true; // it takes longer time if N is a large prime!
} // note: only work for N <= (last prime in vi "primes")^2
// inside int main()
int main()
{
    int TestCase,x;
sieve(1000010); // can go up to 10^7 (need few seconds)

    while(cin >> TestCase)
    {
        x=0;
        while(TestCase >= primes[x])
        {
            x++;
        }
        cout << x << endl;
    }
}