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 <cmath>

using namespace std;

bool isPrime(int n) {
    if (n < 2) {
        return false;
    }
    else if (n == 2) {
        return true;
    }
    else if(n%2 == 0) {
        return false;
    }
    
    double num = sqrt(n);
    for (int i = 3; i <= num; i += 2) {
        if (n%i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    int cnt;
    while(cin >> n) {
        cnt = 0;
        for (int i = 2; i <= n; i++) {
            cnt += isPrime(i);
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(void){
  int n;
  while(scanf("%d",&n)!=EOF){
    if(n==1){
      printf("%d\n",0);
      break;
    }
    int p[50000];
    p[0]=2;
    int pi=1;
    int i=2;
    while(i<=n){
      int t=1;
      int j;
      for(j=0;j<pi;j++){
	if(i%p[j]==0){
	  t=0;
	  break;
	}
      }
      if(t==1){
	p[pi]=i;
	pi++;
      }
      i++;
    }
    printf("%d\n",pi);
  }
  return 0;
}

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

std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 1000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
}

C++: // 2012/11/07 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[1000000];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<1000000; i++){
		is_prime[i] = true;
	}

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

	int n_prime[1000000];

	int cnt = 0;
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			cnt++;
		}

		n_prime[i] = cnt;
	}

	while(true){
		int n;
		cin >> n;

		if(cin.eof())
			break;

		cout << n_prime[n] << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;
 
int main(void)
{
  int input;
  while(cin >> input)
  {
  bool isPrime[input];
  // if the index 0 do not count as the prime number
  isPrime[0] = false;
  /// if the index 1 do not count as the prime number
  isPrime[1] = false;
  // if the index 2 count as the prime number
  isPrime[2] = true;
  
	for(int i = 3; i <= input; i += 2)
    		isPrime[i] = true;
  	
	for(int i = 3; i * i <= input; i += 2)
   		 for(int j = i * i; j <= n; j += i)
     		 isPrime[j] = false;
  		 for(int i = 4; i <= n; i += 2)
    		 isPrime[i] = false;
  
	int count = 0;
 	

	for(int i = 0; i <= input; i++)
    	
	if(isPrime[i])
    	{
     	 count++;
      
    	}
  	cout << count << endl;
  }
}

C++: #include<stdio.h>
int n;
int num[1000000]={0};
int ans=0;

int del(int x){
    for(int i=x;i<999999;i++){
        if(i%x==0){
            num[i]=1;
        }
    }
    return 0;
}

int main(){
    while(scanf("%d",&n)!=-1){
        for(int i=0;i<999999;i++){
            num[i]=0;
        }
        ans=0;
        for(int i=1;i<n+1;i++){
            if(i==1){

            }
            else if(num[i]==0){
                ans++;
                del(i);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include<queue>
#include<stack>
#include<cstdio>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int ans=0;
		int d[999999+100]={};
		for(int i=2;i*i<=n;i++){
			if(d[i]==0){
				for(int j=2;j*i<=n;j++){
					d[j*i]++;
				}
			}
		}
		d[1]=1;
		for(int i=1;i<=n;i++){
					if(d[i]==0){
						ans++;
					}
							}
			cout<<ans<<endl;

		}
		
		return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n,visited,cnt=0;
  
  while(cnt<30){
    int count =0;
    cnt++;
    cin >> n;
    if(n==0)count =0;
    for(int j=2;j<=n;j++){
      visited=0;
      for(int i = 2;i<=n;i++){
	
	if(j%i==0&&j!=i)visited=1;
	else if(j%i==0&&j==i&&visited==0)count++;
	/*	cout<<"j/"<<j<<" i:"<<i <<" count:"<<count<<" visited"<<visited<<endl;    */ 
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

int main(){
	int n;
	int a[1000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

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

int n, sum[1000001], isP[1000001];
vector<int> p;

int main() {
  for (int i = 2; i * i <= 1000000; i++) {
    bool ok = true;
    for (int j = 0; j < p.size(); j++) if (i % p[j] == 0) {
      ok = false;
      break;
    }
    if (ok) p.push_back(i);
  }
  for (int i = 2; i <= 1000000; i++) isP[i] = 1;
  for (int i = 0; i < p.size(); i++) {
    int k = 2;
    while (p[i] * k <= 1000000) isP[p[i] * k] = 0, k++;
  }
  for (int i = 1; i <= 1000000; i++) sum[i] = sum[i-1] + isP[i];
  while (scanf("%d", &n), n) {
    printf("%d\n", sum[n]);
    n = 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;
}