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<stdio.h>

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

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

	while(scanf("%d",&d)!=EOF)
	{
		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 <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

bool prime[1000000];
int ans[1000000];

void is_prime(){
  rep(i,1000000)prime[i]=true;
  prime[0]=prime[1]=false;
  REP(i,2,1000000){
    if(prime[i]==true){
      for(int j=i+i;j<1000000;j+=i)prime[j]=false;
    }
  }
  if(debug)rep(i,1000)if(prime[i])cout<<i<<endl;
}

void calc(){
  ans[0]=0;
  REP(i,1,1000000){
    ans[i]=ans[i-1]+prime[i];
  }
}

int main(){
  int n;
  is_prime();
  calc();
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

C++: #include<stdio.h>
bool b[1000000];

int main(void)
{
    int a,n,i;
    int count=0;
    int f=1;

    for(i=3;i<1000000;i+=2){
        f=1;
        for(a=2;a*a<=i;a++){
            if(i%a == 0){
                f=0;
                break;

            }
        }
        if(f==1){
            b[i]=1;
        }
    }
    b[2]=1;

    while(scanf("%d",&n)!=EOF){
        for(i = 0; i < n; i++){
            if(b[i]==1)count++;
        }

    printf("%d\n",count);
    count=0;
    }
    return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
//aoj0009
using namespace std;
int n,gs;
vector<int> cun;
char ip[1000003];
void prime()
{
	cun.clear();
	gs=0;
	memset(ip,1,sizeof(ip));
	ip[0]=0;
	ip[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(ip[i]==1)
		{
			gs++;
			cun.push_back(i);
			for(int j=2*i;j<=n;j+=i)
			{
				ip[j]=0;
			}
		}
	}
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		prime();
		printf("%d\n",gs);
	}
	return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << n - primes.count() - 1 << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
 
bool CheckPrimeNumber(int number) {
    int max = (int)std::sqrt(number);
    for (int i=3; i<=max; i+=2)
        if (number % i == 0)
            return false;
    return true;
}
 
int main() {
    int n, cnt;
    while (std::cin >> n) {
        if (n < 2) {
	cnt = 0;
        } else if (n == 2) {
	cnt = 1;
        } else {
        	cnt = 1;
        	for (int i=3; i<=n; i+=2)
		if (CheckPrimeNumber(i))
			cnt++;
        }
        std::cout << cnt << std::endl;
    }
    return 0;
}

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


int main() {
  int max =0;
  vector<int> ns;
  vector<int> nums;
  while(!cin.eof()){
    int n=0;
    cin >> n;
    // 求める数の最大値を出す
    max = max > n ? max : n;
    // nsには入力が一覧で入る
    ns.push_back(n);
  }
  for(int i =0 ;i <= max;i++) {
    // 0-maxまで1をいれる。
    nums.push_back(1);
  }

  // 素数の可能性が無いものについては0を入れていく (n >=2)
  for(int i =2 ;i <= max;i++) {
    if(nums[i]==0) {
      continue;
    }
    // 素数の 2～倍はすべて素数ではないのでnを入れる
    for(int ii=i*2 ; ii<=max ; ii+=i) {
      nums[ii] = 0;
    }
  }

  for(int i=0;i<ns.size()-1;i++) {
    int count = 0;
    // 素数の数を数え上げ
    for(int ii=2 ; ii <= ns[i] ; ii++) {
      if(nums[ii]==1) count++;
    }
    cout<<count<<endl;
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
	int i, j, n;
	int count = 0;

	while (cin >> n) {
		for (i = 2; i <= n; i++) {
			for (j = 2; j < i; j++) {
				if (i % j == 0) {
					break;
				}
			}
			if (i == j) {
				count++;
			}
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

C++: #include<iostream>
#define MAX_NUM 1000
using namespace std;

int main(void) {
  int table[MAX_NUM + 1] = {0};
  for(int i = 2; i < MAX_NUM; i++) {
    for(int j = i * 2; j < MAX_NUM; j = j + i) {
      table[j] = 1;
    }
  }

  int num;
  int ans = 0;
  while(cin >> num) {
    for(int i = 2; i <= num; i++) {
      if(table[i] == 0) {
        ans++;
      }
    }
    cout << ans << endl;
    ans = 0;
  }

  return 0;
}

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

int main(){

	int n, i, j, prmnum;
	bool prm = true;
	while(cin>>n){
		prmnum = 0;
		for( i=2;i<=n;i++ ){
			prm = true;
			for( j=2;j<i;j++ ){
				if( i%j == 0 ){
					prm = false;
					break;
				}
			}
			if(prm)prmnum++;
		}
		cout << prmnum << endl;
	}
	return 0;
}

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

int main(){
    vector<int> prime;
    int n;
    for(int i=2;i<1000000;i++){
        bool isprime=true;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                isprime=false;
                break;
            }
        }
        if(isprime) prime.push_back(i);
    }
    while(cin >> n){
        for(int i=0;i<prime.size();i++){
            if(prime[i]>n){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main(){
  int MAX = 1000000;
  int n;
  int cnt=0;
  vector<bool> num(n);
  
  for(int i=0; i<MAX; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;

  for(int i=2; i*i<=MAX; i++){
    if(num[i]){
      for(int j=i*2; j<MAX; j+=i){
	num[j] = false;
      }
    }
  }

  while(cin >> n){
    cnt = 0;
    for(int i=0; i<n; i++){
      if(num[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}