Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

C++: //
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    long in[30];
    long out[30];
    int n = 0;
    long max = 0;
    while(cin >> in[n]){
        if(max < in[n]){
            max = in[n];
        }
        n++;
    }
    //printf("%d", n);
    
    long p[100000];
    //int length = sizeof(p) / sizeof(*p);
    int m = 0;
    //printf("length: %d", length);
    for (int i = 2; i <= max; i++) {
        bool prime = true;
        for(int j = 0; j < m; j++){
            if (i % p[j] == 0) {
                prime = false;
            }
        }
        if (prime) {
            p[m] = i;
            //printf("%ld\n", p[m]);
            m++;
        }
    }
    
    
    for (int i = 0; i < n; i++) {
        int s = 0;
        while (in[i] >= p[s] && p[s] != 0) {
            //printf("in: %ld, p: %ld\n", in[i], p[s]);
            s++;
        }
        out[i] = s;
        printf("%ld\n", out[i]);
    }
    
    return 0;
}

C++: #include <iostream>                                                                                                     
#include <vector>                                                                                                       
                                                                                                                        
using namespace std;                                                                                                    
                                                                                                                        
int main() {                                                                                                            
  int n;                                                                                                                
  int count;                                                                                                            
  while (cin >> n) {                                                                                                    
    if (n == 1) { cout << 0 << endl; continue; }                                                                        
    vector<int> prime_numbers; // 素数リスト                                                                            
    count = 1;                                                                                                          
    for (int i = 2; 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);                                                                                     
        count += 1;                                                                                                     
      }                                                                                                                 
    }                                                                                                                   
    cout << count << endl;                                                                                              
  }                                                                                                                     
  return 0;                                                                                                             
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int vis[1000000];
int n;int sum;
void pre()
{
    memset(vis, 0, sizeof(vis));
for(int i = 2; i <= 999999; i++)
	for(int j = i*2; j <= 999999; j += i)
		vis[j] = 1;
}
int main()
{
    pre();
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        for(int i=2;i<=n;i++)
        {
            if(!vis[i])
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

int primes[78498], num_primes;
int calculated;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	calculated = 2;
	num_primes = 1;
	while (true) {
		int n;
		if (!scanf("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				int max = (int)(sqrt(i)) + 1;
				for (int j=1; primes[j] < max&&j<num_primes; j++) {
					if (i%primes[j] == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

C++: #include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

const int N = 100000

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N+1)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

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

#define MAX_N 2000000
int prime[MAX_N];



int main(){
	prime[1] = 1;
	prime[2] = 0;
	prime[3] = 0;
	for(int i = 2; i<=MAX_N;i++){
		if(prime[i] == 0)
			for(int j=2*i;j<=MAX_N;j=j+i)
				prime[j] = 1;
	}
	
	int n;
	int num=0;
	while(true){
		cin >> n;
		if (cin.eof() ==1)
			break;	
		for(int k = 1;k<=n; k++){
			if(prime[k]==0)
				num++;
		}
		cout << num << endl;
		num = 0;
	}
	return 0;
}

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

int main(){
	int n,count;
	bool num[1000000];
	while( scanf("%d",&n) != EOF ){
		for(int i=2;i<=n;i++){
			num[i]=true;
		}
		count = 0;
		for(int i=2;i<=sqrt(n);i++){
			if(num[i]){
				for(int j=i;j<=n;j+=i){
					num[j]=false;
				}
				 count++;
			}
		}
		for(int i=2;i<=n;i++){
			count += num[i];
		}
		printf("%d\n",count);
	}
	return 0;
}