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

using namespace std;

int main() {
	long n, m;
	int flag;
	long counter;

	long i, len;
	
    while (scanf("%ld", &n) != EOF) {
        counter = 0;
        m = 2;
        
        while (m <= n) {
            flag = 0;
            len = m / 2;
    
            for(i = 2; i <= len; i++) {
                if(m % i == 0) {
                    flag = 1;
                    
                    break;
                }
            }
    
            if (flag == 0) counter++;
    
            m++;
        }
        
        printf("%ld\n", counter);
    }

    return 0;
}

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

void solve(int n) {
	int i, j, ans = 0;
	for (i = 2; i <= n; i++) {
		int num = 0;
		for (j = 2; j <= i; j++) {
			if (i%j == 0) num++;
		}
		if (num == 1) ans++;
	}
	cout << ans << endl;
}

int main() {
	int n;
	while (cin >> n) {
		cin >> n;
		solve(n);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool array[1000000];
		int count=0;
		array[0]=array[1]=false;
		for(int i=1;i<=n;i++){
			if(array[i]){
				count++;
				for(int j=i*2;j<=n;j+=i){
					array[j]=false;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

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

int main(){
	int n;
	while ( cin >> n ){
		bool* table = new bool[ n + 1 ];
		for ( int i = 0; i <= n ; ++i ){
			table[ i ] = false;
		}
		if ( n >= 2 ) table[ 2 ] = true;

		for ( int i = 3; i <= n; i += 2 ){
			table[ i ] = true;
		}
		for ( int i = 3; i <= sqrt( static_cast< double >( n ) ); i += 2 ){
			if ( !table[ i ] ) continue;
			for ( int j = i + i; j <= n; j += i ){
				table[ j ] = false;
			}
		}

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

		cout << cnt << endl;

		delete[] table;
	}
}

C++: #include <stdio.h>
const int MAX_V = 999999;
int main(){
int prime[MAX_V+1]={0};
int sum[MAX_V+2]={0};
int i, k, v ,n;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]) {
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  for(i=0 ;i<=MAX_V+1 ;i++){
    sum[i+1] += sum[i] + prime[i];
  }

  while(scanf("%d" ,&n)){
    if(n==0)break;
     printf("%d\n" ,sum[n+1]);
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans=1;
    int num[n+1]={0};
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      if(num[i]!=0) continue;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        for(int j=1; j<=n; j++){
          if(j*i > n) break;
          num[j*i]=1;
        }
        ans++;
      }
    }
    cout << ans << endl;;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int i,j,n;
	
	
	while(cin >> n){
	int count = 0;
	bool flag[n+1];
		
		for(i=2;i<n+1;i++) flag[i] = true;
		
		for(i=2;i<n+1;i++){
			if(!flag[i]){
				continue;
			}
			for(j=2*i;j<n+1;j+=i){
				flag[j] = false;
			}
		}
		
		// 個数を走査
		for(i=2;i<n+1;i++){
			if(flag[i]==true){
				count++;
			}
		}
		
		cout << count << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cmath>
#define Even(n) n%2
using namespace std;

void count_Prime(int n);
bool IsPrime(int num);


int main()
{
	int Data;

	while (cin >> Data)
	{
		count_Prime(Data);
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 1; i <= n; ++i)
	{
		if (IsPrime(i))
			counter++;
	}

	cout << counter << endl;

}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

C++: #include <iostream>
using namespace std;
 
 
int main()
{
    int max = 10000;
    int prime[max];
    
    fill(prime, prime + max, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < max; i++) {
        if (prime[i]) {
            for (int j = 2*i; j < max; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for(int i = 1;i < max; i++){
	    prime[i] = prime[i] + prime[i-1];
    }
    
    int aaa;
    while (cin >> aaa) {
	cout << prime[aaa] << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int pr[50847534];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
        /*printf("O\n");*/
      return nxp;
    }else{
        /*printf("X\n");*/
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF){
        printf("n=%d\n",n);
        i=0;
        if(n-1){
            while(pr[i]<=n){
                /*printf("prime:%d(%d)\n",pr[i],i+1);*/
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
    }
}

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

const int INF = 1 << 30;
const int MAX_PRIME = 1000010;
bool is_prime[MAX_PRIME + 10];
vector<int> primes;

void init_primes() {
    fill(is_prime, is_prime + MAX_PRIME + 10, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=0; i<=MAX_PRIME; i++) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int k=i+i; k<=MAX_PRIME; k+=i) {
                is_prime[k] = false;
            }
        }
    }
}

int main() {
    init_primes();
    primes.push_back(INF);

    int N;
    while(scanf("%d", &N) != EOF) {
        printf("%zu\n", upper_bound(primes.begin(), primes.end(), N) - primes.begin());
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX 1000000;
int N;

int prime[MAX];


int main(){
	prime[0]=1;
	prime[1]=1;
	prime[2]=0;
	prime[3]=0;
	for(int i=0;i*i<=MAX;i++) {
		if(prime[i]==1) continue;

		for(int t = i*2;t<MAX;t+=i)
			prime[i]=1;
	}

	while(cin.eof()){
		int m = 0;
		cin >> N;
		for(int i =0;i<=N;i++)
			if(prime[i]==0)
				m++;

		cout << m << endl;
	}

	return 0;
}