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 <iostream>                                                                                                       
#include <vector>                                                                                                         
#include <list>                                                                                                           
                                                                                                                          
#define MAX 1000000                                                                                                       
                                                                                                                          
using namespace std;                                                                                                      
                                                                                                                          
int main() {                                                                                                              
  vector<int> prime_numbers;                                                                                              
  prime_numbers.push_back(2);                                                                                             
  prime_numbers.push_back(3);                                                                                             
  prime_numbers.push_back(5);                                                                                             
  prime_numbers.push_back(7);                                                                                             
                                                                                                                          
  list<int> search_list;                                                                                                  
  for (int i = 5; i < MAX; i++) {                                                                                         
    if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0) {                                                           
      search_list.push_back(i);                                                                                           
    }                                                                                                                     
  }                                                                                                                       
  int h = search_list.front();                                                                                            
  while (h * h < search_list.back()) {                                                                                    
    prime_numbers.push_back(h);                                                                                           
    list<int>::iterator itr = search_list.begin();                                                                        
    while (itr != search_list.end()) {                                                                                    
      if (*itr % h == 0) {                                                                                                
        itr = search_list.erase(itr);                                                                                     
      } else {                                                                                                            
        itr++;                                                                                                            
      }                                                                                                                   
    }                                                                                                                     
    h = search_list.front();                                                                                              
  }                                                                                                                       
  for (list<int>::iterator itr = search_list.begin(); itr != search_list.end(); itr++) {                                  
    prime_numbers.push_back(*itr);                                                                                        
  }                                                                                                                       
                                                                                                                          
  int n;                                                                                                                  
  while (cin >> n) {                                                                                                      
    int count = 0;                                                                                                        
    for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) {                          
      if (*itr > n) break;                                                                                                
      count++;                                                                                                            
    }                                                                                                                     
    cout << count << endl;                                                                                                
  }                                                                                                                       
                                                                                                                          
  return 0;                                                                                                               
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

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

constexpr int64_t CALCNUM = 100000;

bool primes[CALCNUM];

signed main()
{
	for(int i = 0; i < CALCNUM; i++)
		primes[i] = true;
    ios::sync_with_stdio(false);
	vector<int> prime;

	for(int i = 2; i <CALCNUM ; i++)
	{
		if(primes[i])
		{
			prime.push_back(i);
			for(int j = 2 * i; j < CALCNUM; j += i)
				primes[j] = false;
		}
	}
	int n;
	while(cin >> n)
	{
		for(int i = 0; i < prime.size(); ++i)
			if(prime[i] > n){
				cout << i <<'\n'; break;
			}
	}
}

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

using namespace std;

int prime(int n) {
  int i, j, r;
  n++;
  vector<int> primes(n);

  for (i = 2; i < n; ++i)
    primes[i] = i;
  for (i = 2; i*i < n; ++i) {
    if (primes[i])
      for (j = i*i; j < n; j += i)
        primes[j] = 0;
  }
  for (i = r = 0; i < n; i++)
    if (primes[i]) r++;
  return r;
}

int main() {
  int n;
  while(cin >> n)
    cout << prime(n) << endl;
  return 0;
}