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 <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, Array = int(1e6);

int main(){

  int n, i, j, maxin = 0;
  bool jud;
  vector <int> vec;

  while(cin >> n){
    if(maxin < n){
      maxin = n;
      for(i = 2;i <= n; i++){
        jud = 0;
        for(j = 0;  j < vec.size() ; j++){
          if( !( i % vec[ j ] ) ){
            jud = 1;
            break;
          }
        }
        if(!jud)
          vec.push_back( i );
      }
    }
    cout << upper_bound(vec.begin(), vec.end(), n) - vec.begin()   <<endl;
  }
}

C++: #include<stdio.h>

int main(void)
{
	int d=0,i,j,s[100000],x;

	for(i=2;i<=100000;i++)
		s[i]=1;

	while(0==0)
	{
		scanf("%d",&d);
	    if(d>1000000)break;
		x=0;
	    for(i=2;i<=d;i++){
	       if(s[i]==1){
		     for(j=i*2;j<=d;j+=i)
			   s[j]=0;
		   }
	    }  
		if(d<=1){
			printf("%d\n",0);
		}
		else
		{
		for(i=2;i<=d;i++){
			x+=s[i];
		}
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 1000000
bool prime[MAX];
int main(void){ 
  
  prime[0] = prime[1] = false;
  //memeset(prime,sizeof(prime),true);
  fill(prime,prime+MAX,true);
  long long int ans[MAX];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  int now=0;
  for(int i = 2 ; MAX > i * i ; i ++){
    ans[i] = now + prime[i];
    now += prime[i];
    //cout<<now<<" "<<ans[i]<<endl;
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  //cout<<"fin"<<endl;
  //for(int i = 0 ; i < 1500 ; i ++)cout<<i<<" "<<ans[i]<<endl;
  int n;
  while(cin>>n){
    if(n>1500)cout<<168<<endl;
    else cout<<ans[n]<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
int a,i;
for(;;){
cin>>a;
for(int x=2x<a;x++){
if(a%x>0){i++}
cout<<i<<endl;
}
}
return 0;
}

C++: #include"stdio.h"

int p[1000000];
int i,j,f;
int n;
int ans;

int main(){
	while(scanf("%d",&n)!=EOF){
		ans=0;
		for(i=2;i<=n;i++)p[i]=1;
		for(i=2;i<=n;i++)if(p[i]==1){
			ans++;
			for(j=2;i*j<=n;j++)p[i*j]=0;
		}
		printf("%d\n",ans);
	}
}

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

int main(){
    int ans,n;
	while(1){
		ans=0;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			cout<<0<<endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=9){
				for(int i=9;i<=n;i+=2){
			        int prime=1;
				    for(int k=3;k<=sqrt(i);k+=2){
					    if(i%k==0){
						    prime=0;
						    break;
    					}
					}
				    if(prime)ans++;
				}
			}
		cout<<ans<<endl;
		}
	}
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

#define MAX 999999

using namespace std;

int main()
{
    int n;
    int num_prime[MAX+1];
    bool not_prime_flag[MAX+1];

    for (int i = 2; i < MAX+1; ++i) {
        if(!not_prime_flag[i]){
            for (int j = 2; i*j < MAX+1; ++j) {
                not_prime_flag[i*j]= true;
            }
        }
        num_prime[i]=num_prime[i-1]+!not_prime_flag[i];
    }
    while (cin>>n){
        cout<<num_prime[n]<<endl;
    }
    return 0;
}

C++: import sys

def prime_list(n):
    l = range(2,n+1)
    i = 2
    while i * i <= n: 
        l = filter(lambda x: x == i or x % i != 0, l)
        i = i + 1
    return l

if __name__ == '__main__':
    l = prime_list(999999)
    for line in sys.stdin:
        n = int(line)
        print len([x for x in l if x <= n])

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

using namespace std;

void Eratosthenes(vector<int> &S_List, vector<int> &P_List){
	vector<int>::iterator it = S_List.begin();
	P_List.push_back(*it);  //先頭を素数リストへ追加
	int num = *it;
	while (it != S_List.end()){
		if ((*it % num) == 0){
			it = S_List.erase(it); //探索リストから倍数を除外
		}
		else{
			++it;
		}
	}
	vector<int>::iterator P_it = max_element(P_List.begin(), P_List.end());
	double p_max_sqr = sqrt(*P_it);
	vector<int>::iterator S_it = max_element(S_List.begin(), S_List.end());
	if (S_List.empty() == true){
		return;
	}
	if (*S_it < p_max_sqr){
		return;
	}
	else{
		Eratosthenes(S_List, P_List);
	}
}


void output(vector<int> ex){
	vector<int>::iterator it = ex.begin();
	while(it != ex.end()){
		cout << *it << endl;
		++it;
	}
}

int main(void){
	int num;
	while (cin >> num){
		vector<int> S_List, P_List;
		for (int i=2; i<=num; ++i){
			S_List.push_back(i);
		} 
		Eratosthenes(S_List, P_List);
		output(P_List);
	}
	return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>

std::vector<std::size_t> prime_table = {2};

void make_prime_table(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        std::set<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            undefined_table.insert(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; ; ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(0 == *u % prime_table[p])
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(!undefined_table.empty() && found_last_prime <= prime_table[p])
            {
                prime_table.push_back(*undefined_table.begin());
                undefined_table.erase(undefined_table.begin());
            }
            if(sn < prime_table.back())
            {
                break;
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
}

std::vector<size_t> prime_acc = {0};

std::size_t prime_size(const std::size_t limit)
{
    if(prime_acc.size() <= limit)
    {
        make_prime_table(limit);
        auto it = prime_table.begin();
        while(prime_acc.size() <= limit)
        {
            it = std::lower_bound(it, prime_table.end(), prime_acc.size());
            if(it != prime_table.end())
            {
                prime_acc.insert(prime_acc.end(), *it - prime_acc.size(), prime_acc.back());
                prime_acc.push_back(prime_acc.back() + 1);
            }
            else
            {
                prime_acc.insert(prime_acc.end(), limit - prime_acc.size() + 1, prime_acc.back());
            }
        }
    }
    return prime_acc[limit];
}

int main()
{
    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_size(n) << std::endl;
    }
}