Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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

int main(){
    bool isPrime[n_size];
    isPrime[0]=false; isPrime[1]=false;

    for(unsigned i=2;i<n_size;i++)
        isPrime[i] = true;

    for(unsigned i=2;i*i<n_size;i++){
        if(isPrime[i]){
            for(unsigned j=(i*i);j<n_size;j+=i)
                isPrime[j] = false;
        }
    }

    unsigned n_prime[n_size];

    unsigned cnt = 0;
    for(unsigned i=0;i<n_size;i++){
        if(isPrime[i])
            cnt++;
        n_prime[i] = cnt;
    }

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

    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	int DataSet,nCnt,nCnt2,In,Total,Count;

	Total = 0;
	DataSet = 0;

	for (DataSet = 0; DataSet <= 30; DataSet++)
	{
		scanf("%d", &In);
		Total = 1;

		if (In > 2)
		{
			for (nCnt = 3; nCnt <= In; nCnt += 2)
			{
				Count = 0;

				for (nCnt2 = 3; nCnt2 <= sqrt((double)nCnt); nCnt2+=2)
				{
					if (nCnt%nCnt2 == 0)
					{
						if (nCnt != nCnt2)
						{
							Count++;
							break;
						}
					}
				}
				if (Count == 0)
					Total++;
			}
		}

		printf("%d\n", Total);
	}


	return 0;
}

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

int main(void){
	
	int a[1000001],b[100000],s,t,x;
	int n,N,m;
	
	a[0]=0;
	b[0]=2;
	m=1;
	N=1;
	
	for(s=3;s<1000000;s=s+2){//?????°????´???°??????
		
		for(t=0;t<N;t++){//???????????§????´???°??§??????
			
			if(s%b[t]==0){//????????????????????????
				break;
			}
			
			if(t==N-1||b[t]>=sqrt((double)s)){//???????????§?????£??????
				
				for(;m<s;m++){//????????°????????????
					
					a[m]=N;
				}
				b[N]=s;//??°???????´???°???????´????
				N++;//?´???°????????°????¢???????
				a[s]=N;
				break;
			}
		}
		
	}
	a[1]=0;
	for(;m<1000001;m++){//????????°????????????
		
		a[m]=N;
	}
	/*for(int x=0;x<1001;x++){
		
		printf("%d %d\n",x,a[x]);
	}*/
	
	while(1){
		scanf("%d",&x);
		printf("%d\n",a[x]);
	}
	return 0;
}

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;
}