Go: package main

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

func search(min, max int, channel chan int) {
	flag := false
	count := 0
	for i := min; i <= max; i++ { //1を除く入力値以下の数字
		for j := 2; j < i; j++ {
			if i%j == 0 {
				flag = true
				break
			}
		}
		if !flag {
			count++
		} else {
			flag = false
		}
	}
	channel <- count
	return
}

func main() {
	count := 0
	channel := make(chan int)
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		for i := 2; i < num; i += 10 {
			if i+10 < num {
				count++
				go search(i, i+10, channel)
			} else {
				count++
				go search(i, num, channel)
			}
		}
		var ans int
		for i := 0; i < count; i++ {
			ans += <-channel
		}

		fmt.Println(ans)
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	vector<long long int>D(1000001 , 1);
	D[0] = 0;
	D[1] = 0;
	for(long long int i = 2; i <= sqrtl(1000001); i++)
	{
		if(D[i])
		{
			long long int j = 2;
			while(i*j < 1000001)
			{
				D[i*j] = 0;
				j++;
			}
		}
	}
	for(long long int i = 1; i < 1000001; i++)
	{
		D[i] += D[i - 1];
	}
	long long int n;
	while(cin >> n)cout << D[n] << endl;
	return 0;
}

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

using namespace std;


void initialize(vector<int> &search_list, int num);

void era(vector<int> &search_list, vector<int> &prime_list, int num);
  

int main(int argc, char* argv[]){
  
  int num;

  while (cin >> num){
    if (num == 1){
      cout << 0 << endl;
    }
    else{
      vector<int> search_list, prime_list;
      initialize(search_list, num);
      era(search_list, prime_list, num);
      cout << prime_list.size() << endl;
    }
  }
  return 0;
}

void initialize(vector<int> &search_list, int num){
  for (int i=2; i<=num; ++i){
    search_list.push_back(i);
  }
  return;
}

void era(vector<int> &search_list, vector<int> &prime_list, int num){
  do{
    vector<int>::iterator it = search_list.begin();
    int count = 1;
    int N = *it;
    prime_list.push_back(*it);
    while ((N*count) <= num){
      it = find(search_list.begin(), search_list.end(), (N*count));
      if (it != search_list.end()){
	it = search_list.erase(it);
      }
      ++count;
    }
  } while (!search_list.empty());
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1000000

static bool gosei[MAX];

void b() {
	for (int i = 2; i <= sqrt(MAX); i++)
		if (gosei[i] == false) {
			for (int j = 2, k = 0; (k = i*j) <= MAX; j++)
				gosei[k] = true;
		}
}

int c(int n) {
	int cnt = 0;
	for (int i = 2; i <= n; i++)
		if (!(gosei[i]))cnt++;
	return cnt;
}

int main() {
	b();
	int n;
	while (cin >> n)
		cout << c(n) << endl;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;

  vector<int> nums;
  nums.reserve(n+1);
  for (int i = 0; i <= n; i++)
    nums.push_back(i);

  for (int i = 2; i <= n; i++) {
    if (nums[i] == 0)
      continue;
    int hoge = nums[i];
    for (int j = i+1; j <= n; j++) {
      if (nums[j] == 0)
        continue;
      else if (nums[j] % hoge == 0)
        nums[j] = 0;
    }
  }

  int result = 0;
  for (int i = 2; i <= n; i++)
    if (nums[i])
      result++;
  cout << result << endl;
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#define N 1000000
int n;
bool prime[N];
int num[N];
int main() {
    memset(prime, 1, sizeof prime);
    //for (int i=0;i<N;++i)prime[i]=true;
    prime[1] = prime[0] = num[0] = false;
    for (int i = 2; i < N; ++i)
        if (prime[i]){
            for (int j = 2 * i; j < N; j += i) prime[j] = false;
        //if (i%1000==0)
        //printf("%d %d\n",i,prime[i]);
    }
    for (int i = 1; i < N; ++i) num[i] = prime[i] + num[i-1];
    while (~scanf("%d", &n)) printf("%d\n", num[n]);
    return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main()
{
    int n;
    set<int> prime;
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            bool is_prime = true;
            int tmp = 2;
            for(auto num : prime)
            {
                if(num >= i) break;
                if(i % num == 0)
                {
                    is_prime = false;
                    break;
                }
                tmp = num;
            }
            for(int j = tmp; is_prime && j <= i / 2; j++)
            {
                if(i % j == 0)
                {
                    is_prime = false;
                    break;
                }
            }
            if(is_prime) 
            {
                prime.insert(i);
            }
        }
        int cnt = prime.size();
        for(auto it = prime.rbegin(); it != prime.rend(); it++)
        {
            cerr << *it << ' ';
            if(n < *it) cnt--;
            else break;
        }
        cout << cnt << endl;
    }
}

C++: // AOJ 009

#include <iostream>
#define MAX_NUMBER 50 //1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples (int prime) {
	for (int i = prime*2; i < MAX_NUMBER;i+=prime) {
		isPrime[i] = false;
	}
	return;
}	

int CountPrimes(int n) {
	int count = 0;
	for (int i = 1;i <= n;i++) {
		if (isPrime[i]) count++;
	}
	return count;
}

int main() {
	for (int i = 0;i < MAX_NUMBER;i++) {
		isPrime[i] = true;	
	}
	isPrime[1] = false;
	
	for (int i = 1;i < MAX_NUMBER;i++) {
		if (isPrime[i]) {
			SetFalseToMultiples(i);
		}
	}
	int n;
	while (cin >> n) {
		cout << CountPrimes(n) << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

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

int main(){
	int n;
	while(cin>>n){
		int sum=1;
		for(int i=3;i<=n;i+=2){
			if( isPrime(i) )sum++;
		}
		if(n==1)sum=0;
		cout<<sum<<endl;
	}
}

C++: // 2015/05/19 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>
#include <cmath>
using namespace std;
int main(){
    int n;
    char prime[1000000] = {1, 1};
    for(int k = 2; k < 1000; k++){
        if(prime[k] == 0){
            for(int j = k * k; j < 1000000; j += k)
                prime[j] = 1;
        }
    }
    while(cin >> n){
        int res = 0;
        for(int j = 2; j <= n;j++) 
			if(prime[j] == 0) 
				res++;
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int k, n, s, t, i = 0, j, maxV = INT_MIN, A[30] = {};
	while (cin >> k) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0;
	bool isP = false;
	for (k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			t = (s - 1) / k;
			for (j = 2; j <= t; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}