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>
#include <vector>
#include <algorithm>
#define N 500000
using namespace std;

int main(){

  int n;
  int a,b,i;
  int sosu[N];
  bool judge;

  sosu[0] = 2;
  for(a=3,i=1;a<1000000;a++){
    judge = true;
    for(b=0;sosu[b]*sosu[b] <= a;b++){
      if(a%sosu[b] == 0){
	judge = false;
	break;
      }
    }
    if(judge){
      sosu[i] = a;
      i++;
    }
  }
  sosu[i] = 1000000;
  while(cin >> n){
    if(0<n && n<1000000){
      for(i=0;sosu[i]<=n;i++);
      cout << i << endl;
    }
  }

  return 0;
}

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

using namespace std;

void Eratosthenes(vector<int> &S_List, vector<int> &P_List){
	while(1){
		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;
	}*/
	cout << ex.size() << endl;
}

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<iostream>
#include<cstdio>
int cnt,n,prime[1000000];
using namespace std;

void count()
{
	int tt=0,flag;
	prime[tt++]=2;
	for(int i=3;i<=n;i++)
	{
		flag=1;
		for(int j=0;prime[j]*prime[j]<=i;j++)
		{
			if(i%prime[j]==0)
			{	
			    flag=0;
		     	break;
			}
		}
		if(flag==1) prime[tt++]=i;
	}
	cout << tt << endl;
}

int main()
{
	while(true)
	{
	   cin >> n;
	   if(n==1){
	   	cout << 0 << endl;
	   	continue;
	   }
	   count();
    }
}

C++: #include <stdio.h>
 #include <string.h>
int main(void) {
    int n,i,c,k,prime[999999] = {0},t;
    for(i = 2; 999999 >= i; i++){
        if(!prime[i])
    		for(c = i*2; 999999 >= c; c += i)prime[c] = 1;
    }
    while(scanf("%d",&n) != EOF){
    	i = 0;
    for(c = 2; n >= c; c++){
        	if(!prime[c]) i++;
        }
    printf("%d\n",i);
    }
     
    return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int prime[80000];
	int ptr=2;
	prime[0] = 2;
	prime[1] = 3;
	for(int num=5; num<1000000; num+=2){
		bool f = false;
		for(int i = 0; i<ptr; i++){
			if (prime[i]*prime[i] > num) break;
			if (num%prime[i]==0) {
				f = true;
				break;
			}
		}
		if(!f) prime[ptr++] = num;
	}
	prime[ptr]=1000001;
	int n;
	while(cin >> n){
		int k=0;
		for(;prime[k]<=n;k++);
		cout << k << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#define MAX 100000
using namespace std;

int main(){
  //bool num[MAX];
  pair<bool,int> num[MAX];
  int input=0;
  while( cin >> input){
   int count=0;
  for(int i=2; i<MAX; i++){
    num[i].first=true;
    num[i].second=i;
  }
  for(int i=2;i<input+1;i++){
    if(num[i].first){
      //cout << num[i].second <<",";
      count++;
      for(int j=i+i; j<MAX; j+=i){
        num[j].first=false;
      }
    }
  }
  cout << count << endl;
  }
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int n;
	while(cin >> n){
		vi pn(1000000,1);
	pn[0]=0;
	pn[1]=0;
	int ans=0;
	for(int i=2;i<=n;i++){
		if(pn[i]==1){
			for(int j=i+1;j<=n;j++){
				if(!(j%i)){
					pn[j]=0;
				}
			}
		}
	}
	rep(i,n+1){
		if(pn[i])ans++;
	}
	cout << ans << endl;
	}


}

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, MAX_N = int(1e6);


int main(){

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

C++: #include <iostream>
using namespace std;
int main(){
  int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;
  int n,c,i;

	int primeNum[NUM];
	for(int i=0;i<NUM;i++){
		if(prime[i])c++;
		primeNum[i] = c;
	}
	while(cin>>n){
		cout<<primeNum[n]<<endl;
		//for(c=0,i=0;i<=n;i++)if(prime[i])c++;
		//cout<<c<<endl;
	}
}

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

int main(){
	int yaku = 0,n,hoge = 0;
	while(cin >> n){
		hoge = 0;
		if(n > 2){
			for(int i = 3;i <= n;i += 2){
				yaku = 0;
				for(int j = 3;j <= sqrt((double)i);j = j + 2){
					
					if(i % j == 0){
						yaku++;
						break;
					}
				}
				if ( yaku == 0)	hoge++;
			}
			
			hoge++;
		}else	hoge == 1;
		cout <<  hoge << endl;

	}

}