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 <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>


/*
	HOME-  Volume0-0009
	Submit Statistics
	 
	PCK 2003
	Prime Number
	Time Limit : 1 sec, Memory Limit : 32768 KB
	English version is here
	Prime Number

	6 ÈºÌ³Ì® n ðüÍµAn ÈºÌfª¢­Â é©ðoÍ·évOðì¬µÄº³¢B½¾µAfÆÍ 1 Æ©ª©gÅµ©èØêÈ¢³Ì®Ì¤¿ 1 ðÌ¼¢½àÌð¢¢Ü·Bá¦Î 10 ÈºÌfÍA2, 3, 5, 7 Å·B
	Input

	¡Ìf[^Zbgª^¦çêÜ·Bef[^ZbgÉ n ªPsÉ^¦çêÜ·BüÍÌÅãÜÅµÄº³¢B
	Output

	ef[^Zbg²ÆÉAn ÈºÌfÌÂðPsÉoÍµÄº³¢B
	Sample Input

	10

	Output for the Sample Input

	4

*/

using namespace std;


int main()
{
	string s;
	
	while (getline(cin, s))
	{
		int n;
		sscanf(s.c_str(), "%ld", &n);
		
		vector<int> v(n, 1);
		printf("t\n");
		
		v[0] = 0;
		v[1] = 0;

		int x = n - 2;

		for (int i = 2; i <= n; i++)
		{
			if (0 == v[i])
			{
				continue;
			}
			for (int k = i * 2; k <= n; k++)
			{
				if (0 == (k % i))
				{
					if (1 == v[k])
					{
						x--;
					}
					v[k] = 0;
				}
			}
		}
		
		printf("%d\n", x);
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

vector<bool> a;
void func(int n){

  for(int i = 0; i <= n; i++){
    a.push_back(true);
  }
  for(int i = 2; i * i <= n; i++){
    if(a[i]){
      for(int j = 2; i * j <= n; j++){
        a[i * j] = 0;
      }
    }
  }
  int cnt = 0;
  for(int i = 2; i <= n; i++){
    if(a[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}

int main(){
  int n;
  while(cin >> n){
    func(n);
  }
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for (int a = 3; a<1000000; a++)
	{
		prime[a] = 1;
	}

	for (int a = 3; a<1001; a++)
	{
		if (checked[a] == 0)
		{
			checked[a] = 1;
			for (int b = 2; b<a; b++)
			{
				if (a%b == 0)
				{
					prime[a] = 0;
					break;
				}
			}
			if (prime[a] == 1)
			{
				for (int c = 2 * a; c<1000000; c += a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for (int a = 3; a<1000000; a++)
	{
		primesum[a] = primesum[a - 1] + prime[a];

	}

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

	return 0;
}

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

/** Problem0009 : Prime Number **/
#define MAX 1000000

int main()
{
	bool prime[MAX];
	int  input, count;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin >> input) {
		count = 0;
		for (int i=0; i<=input; i++) {
			if (prime[i]) count++;
		}
		cout << count << endl;
	}
}

C++: #include <iostream>                                                                                                     
#include <vector>                                                                                                       
                                                                                                                        
using namespace std;                                                                                                    
                                                                                                                        
int main() {                                                                                                            
  int n;                                                                                                                
  cin >> n;                                                                                                             
                                                                                                                        
  if (n == 1) { cout << 0 << endl; return 0; }                                                                          
  if (n == 2) { cout << 1 << endl; return 0; }                                                                          
                                                                                                                        
  vector<int> prime_numbers; // 素数リスト                                                                              
  int c = 1;                                                                                                            
  prime_numbers.push_back(2);                                                                                           
  for (int i = 3; i <= n; i++) {                                                                                        
    bool prime = true;                                                                                                  
    for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) {                        
      if (i % *itr == 0) {                                                                                              
        prime = false;                                                                                                  
        break;                                                                                                          
      }                                                                                                                 
    }                                                                                                                   
    if (prime) {                                                                                                        
      prime_numbers.push_back(i);                                                                                       
      c += 1;                                                                                                           
    }                                                                                                                   
  }                                                                                                                     
  cout << c << endl;                                                                                                    
  return 0;                                                                                                             
}