Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000005]={0};
	for(int i=2;i<1000000;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		if(flag){
		sosu[i]=1;
		}
	}
	while(cin>>n){
	ans=0,cnt=0;
	for(int i=2;i<=n;i++){
		if(sosu[i]==1){
		ans++;
		}
	}
	cout<<ans<<endl;
	}
    return 0;
}

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

using namespace std;

int prime(int a){
    int sqt = sqrt(a);
    int *array = new int[a+1];
    array[1] = 1;
    array[2] = 0;
    array[3] = 0;
    if(a >= 4){
        for(int i = 2; i <= sqt; i++){
            for(int j = 2; j*i <= a; j++){
                array[i*j] = 1;
            }
        }
    }
    int count = 0;
    for(int i = 1; i <= a; i++){
        if(array[i] == 0) count++;
    }
    return count;
}

int main(){
    int n;
    while(cin >> n){
        cout << prime(n) << endl;
    }
}

C++: #include<stdio.h>  
#include<math.h>
  
int main(void)
{  
	//入力変数
    int n = 0;  
	//素数判定flag
    bool isPrime = true;
	//素数カウント変数
    int count = 0;  
	//素数格納配列
    int prime[100000];  
	//ループの最高回数
	int imax = 0;
  
    while(scanf("%d", &n) != EOF) 
	{  
        count = 0;  
  
		//2は特別扱い
		if (n >= 2)
		{
	        prime[0] = 2;  
			count++;
		}

		//2の倍数はいらない
        for(int j = 3; j <= n; j += 2) 
		{  
			//素数かそうでないかの判断をするflag
			isPrime = true;  
  
			//平方根を求める
			imax = sqrt(double(j));

			//ここでエラトステネスのふるいで使った平方根の考え方を利用
            for(int i = 0; prime[i] <= imax; i++)
			{  
                if(j % prime[i] == 0)
				{  
                    isPrime = false;  
                    break;  
				}  
			}

			//素数だった場合
		    if(isPrime == true) 
			{  
				prime[count++] = j;  
			}  
		}  
  
		printf("%d\n", count);  
  
    }  
  
    return 0;  
}

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

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

C++: #include<iostream>

using namespace std;

int get_numprime( int num );
bool prime( int n );


int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		cout << get_numprime( num ) << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 0;

	for( int i = 2 ; i <= num ; i++ )
	{
		if( prime(i) ) numprime++;
	}

	return numprime;
}

bool prime( int n )
{
	for( int i = 2 ; i <= n/2 ; i++ )
	{
		if( n%i == 0 )
		{
			return false;
		}
	}
	return true;
}

C++: //#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;

#define N_MAX 1000000

int kouho[N_MAX / 2];

int main(){

	//clock_t c1,c2;
	//c1 = clock();

	vector <int> sosuu;
	int check;
	//int kouho[N_MAX / 2];
	int n;
	int cnt;


	for (int i = 0; i < N_MAX / 2; i++){
		kouho[i] = i * 2 + 1;
	}
	kouho[0] = 0;

	sosuu.push_back(2);
	check = 3;

	while (check < 1000){
		sosuu.push_back(check);
		for (int i = check; i < N_MAX; i += (check*2)){
			kouho[(i - 1) / 2] = 0;
		}

		for (int i = check/2; i < N_MAX / 2; i++){
			if (kouho[i] != 0){
				check = kouho[i];
				break;
			}
		}
	}


	
	while (cin >> n){
		cnt = 0;
		if (n <= 1000){
			for (int i = 0; i < sosuu.size(); i++){
				if (sosuu[i] <= n)cnt++;
				else break;
			}
		}
		else{
			cnt += sosuu.size();
			for (int i = 0; i < N_MAX /2; i++){
				if (kouho[i] > n){
					break;
				}
				else{
					if (kouho[i] != 0)cnt++;
				}
			}
		}
		cout << cnt << endl;
	}

	//c2 = clock();

	//cout << "time = " << (double)(c2 - c1) / CLOCKS_PER_SEC << "[sec]" << endl;


	return 0;
}

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

int main(){
  int n,prime[1000000],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=999999;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  cin >> n;
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;

}

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

#define MAX 1000000

using namespace std;

int n, num[MAX];
bool isp[MAX];

void sieve() {
	for(int i = 2; i < MAX; i++)
		isp[i] = true;
	for(int i = 2; i * i < MAX; i++)
		if(isp[i])
			for(int j = i * i; j < MAX; j += i)
				isp[j] = false;

	num[0] = num[1] = 0;
	for(int i = 2; i < MAX; i++)
		num[i] = num[i-1] + isp[i];
}

int main() {
	sieve();
	while(cin >> n)
		cout << num[n] << endl;
	return 0;
}

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

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[1000000];
  int num;
  int nump=0;
  int cnt=0;

  set_prime_number(prime_number,1000000);
	while(scanf("%d",&num)!=EOF){
	 for (int i = 0; i <= num; i++) {
		 if (prime_number[i]){cnt++;}
	 }
	 printf("%d\n",cnt);
	 cnt=0;
	}


  return 0;
}

C++: #include <iostream>
//#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		//result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

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

int main(){
  
  int n;

  while(cin >> n){
    bool Prime[1000000] = {};
    int i,j,count;
    count = n;
    for(i = 2; i <= sqrt(n) ; i++){
      if(Prime[i] == false){        
	for(j = 2; i*j <= n ; j++){
	  if(!Prime[i*j]){
	    Prime[i*j] = true;
	    count--;
	  }
	}
      }
    }
    cout << count-1 << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int prime(int n)
{
    int a,b;
    if(n==(0||1)) return 0;
    else if (n==2) return 1;
    else if(n%2==0) return 0;
    a=sqrt(n);
    for(b=3;b<=a;b+=2)
    {
        if(n%b==0) return 0;
    }
return 1;
}
int main()
{
    int n,i,j,k;
    for(k=1;k<=30;k++)
    {
        cin>>n;
        j=0;
        for(i=1;i<=n;i++)
        {
            if(prime(i)==1) j++;
        }
    cout<<j<<endl;
    }
}