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

const int MAX_N = 1000000;

vector<int> init(void){
    vector<int> prime;
    bool is_prime[MAX_N];
    memset(is_prime, true, MAX_N);
    
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<MAX_N; i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i; j<MAX_N; j+=i) is_prime[j] = false;
        }
    }
    return prime;
}

int main(int argc, const char * argv[])
{
    int n;
    vector<int> prime = init();
    while(cin>>n){
        cout << upper_bound(prime.begin(), prime.end(), n)-prime.begin() << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,i,j;
    int ans;
    cin >> n;
    //while(cin >> n){ 
        ans=0;
        for(i=2;i<=n;i++){
            for(j=2;j<=i;j++)
                    if(i%j==0){
                        
                        //nの因数iが素数かどうかを判定する
                        //割り切れたら素数じゃないのでループ抜ける
                        
                        break;

            }
                    //jが最終まで行けばiが素数なのでans++
                    if(j==i)ans++;
        }
        cout << ans << endl;
    //}
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#define maxn 1000000
using namespace std;
int prime[maxn],number[maxn];
void getprime()
{
    int m=sqrt(maxn+0.5);
    for(int i=2;i<=m;i++)
    {
        if(!prime[i])
        {
            for(int j=i+i;j<maxn;j+=i)
            {
                prime[j]=1;
            }
        }
    }
    int sum = 0;
    for(int i=2;i<maxn;i++)
    {
        if(!prime[i])
        {
            sum++;
        }
        number[i]=sum;
    }
}
int main ()
{
    int n;
    getprime();
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",number[n]);
    }
}
/**
--------------------- 
???zhaiqiming2010 
???CSDN 
???https://blog.csdn.net/zhaiqiming2010/article/details/62281598 
?????????????????????????
**/

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

int main() {

  int x;
  int count_cin = 0;
  while(true){
    cin >> x ;
    count_cin++;

    if(count_cin == 30) break;


    bool array[max_n];

    for(int i = 0; i < max_n; i++) {
      array[i] = true;
    }

    array[0] = false;
    array[1] = false;
    for(int i = 2; i < max_n; i++) {
      for(int j = 2; j < max_n; j++) {
        if(i * j > max_n) break;
        array[i * j] = false;
      }
    }

    int count_sosu = 0;

    for(int i = 0; i < x; i++) {
      if(array[i] == true) count_sosu++;
    }

    cout << count_sosu << endl;
  }

}

C++: /*
 * fudq.cpp
 *
 *  Created on: 2015-10-24
 *      Author: bjfudq
 */
#include <functional>
#include <algorithm>
#include <iostream>
//#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")


#define MEM(a) (memset((a),0,sizeof(a)))
#define LEN(a) (int)strlen((a))
#define fr(a) for(int i=0;i<(a);i++)
#define sf(a) scanf("%d",&(a))
#define sf64(a) scanf("%I64d",&(a))
#define sff(a) scanf("%lf",&(a))
#define sfs(a) scanf("%s",(a))
#define sf2(a,b) scanf("%d%d",&(a),&(b))
#define sf3(a,b,c) scanf("%d%d%d",&(a),&(b),&(c))
#define sf2s(a,b) scanf("%s%s",(a),(b))
#define sf2f(a,b) scanf("%lf%lf",&(a),&(b))
#define sf3f(a,b,c) scanf("%lf%lf%lf",&(a),&(b),&(c))
#define sf264(a,b) scanf("%I64d%I64d",&(a),&(b))
#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&(a),&(b),&(c))
#define pf(a) printf("%d\n",(a))
#define pfc(a) printf("%c",(a))
#define pf64(a) printf("%I64d\n",(a))
#define pff(a) printf("%lf\n",(a))
#define pfs(a) printf("%s\n",(a))
#define pf2(a,b) printf("%d %d\n",(a),(b))
#define pf2s(a,b) printf("%s%s\n",(a),(b));
#define pf2f(a,b) printf("%lf %lf\n",(a),(b))
#define pf264(a,b) printf("%I64d %I64d\n",(a),(b))
#define pfn printf("\n")
#define pfk printf(" ")
#define LL long long

const int N=1000010;
const int M=1000010;
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const int dir4[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
const int dir8[8][2]={{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};
const double eps=1e-12;
const double PI=acos(-1.0);

inline int sign(double x){return (x>eps)-(x<-eps);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
/*************************/

int tot,prime[N+10],f[N+10];

void Getprime()
{
	memset(f,0,sizeof(f));
	tot=0;
	for(int i=2;i<=N;i++)
	{
		if(f[i] == 0)
			prime[tot++]=f[i]=i;
		for(int j=0;j<tot && prime[j]<=f[i] && i*prime[j]<=N;j++)
			f[i*prime[j]]=prime[j];
	}
}



int main(){
    Getprime();
    int n;
    while(sf(n)!=EOF){
    	int p=lower_bound(prime,prime+tot,n)-prime;
    	if(prime[p] != n) p--;
    	pf(p+1);
    }
    return 0;
}

C++: #include <algorithm>
#include <climits>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map> //pair is also included in this library
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

using namespace std;

typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;

//prefer define statement
//for reason that const int ver. of INF will raise a silly warning (unused variable)
#define INF (INT_MAX/3)
#define LIM_INF (INT_MAX)
//const int INF = INT_MAX/3;

/*------------------------------------------------------------------------------*/



int main(){
  int n = 1000000;
  vector<bool> p(n, true);
  p[0] = false;
  p[1] = false;

  REP(i, 2, n){
    if(p[i]){
      for(int j = i * 2; j < n; j += i){
        p[j] = false;
      }
    }
  }
  
  int N;

  VI v(n, 0);
  REP(i, 1, n){
    if(p[i]){
      v[i] = v[i-1] + 1;
    } else {
      v[i] = v[i-1];
    }
  }
  while(cin >> N){
    cout << v[N] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

int main(){
	int n;
	vector<int> prime;
	int count[100002];
	
	//cout<<"hoge\n";
	prime.push_back(2);
	prime.push_back(3);
	count[1]=0;
	count[2]=1;
	count[3]=2;
	//cout<<"hoge\n";
	for(int i=4;i<10000;i++){
		if(i%2==0){
			count[i]=prime.size();
		}
		else if(i%3==0){
			count[i]=prime.size();
		}
		else{
			count[i]=prime.size()+1;
			prime.push_back(i);
			for(int j=0;j<prime.size()-1;j++){
				if(i%prime[j]==0){
					count[i]--;
					prime.pop_back();
					break;
				}
			}
		}
	}
	//cout<<"hoge";
	/*for(int i=0;i<15;i++){
		cout<< count[i] << endl;
	}*/
	while(cin>>n){
		cout<<count[n]<<endl;
	}
	return 0;
}