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 <iostream>
#include <algorithm>
#include <deque>
using namespace std;


int main()
{

	int i,n,count,num;
	deque<int> sosu;
	deque<int>::iterator it;
	bool flg;
	
	while(cin >> n){
		sosu.clear();
		if( n <= 2 ) {
			if( n == 2 ) {
				count = 1;
			}
			else 
				count = 0;
		}
		else {
			for( i = 3; i <= n ; i+=2 ) {
				flg = true;	
				for(it = sosu.begin(); it != sosu.end(); it++ ) {
					num = *it;
					if( i < 2 * num ){
						break;
					}
					if( (i % num ) == 0 ){
						flg = false;
						break;
					}				
				}
				if( flg == true ) {
					sosu.push_back( i );
				}
			}
			count = sosu.size() + 1;
		}
		cout << count << endl;
	}
			
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
    int N;
    int count=0;
    cin >> N;
    bool* IsPrime = new bool[N];
    IsPrime[0] = false;
    IsPrime[1] = false;
    for(int i=2; i<=N;i++){
      IsPrime[i] = true;
    }
    for(int i=2; i*i<=N;i++){
      if(IsPrime[i]){
        for(int j=2*i; j<=N; j+=i)
          IsPrime[j] = false;
        }
    }
    for(int i=0; i<=N;i++)
      if(IsPrime[i]) count++;
    
    cout << count << endl;
    delete[] IsPrime;
    return 0;
}

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

std::vector<std::size_t> prime_table = {2};

void make_prime_table()
{
    std::set<std::size_t> undefined_table;
    for(std::size_t i = 3; i <= 999999; ++i)
    {
        undefined_table.insert(i);
    }

    const std::size_t sn = 1000;
    for(std::size_t p = 0; !undefined_table.empty() && p < prime_table.size(); ++p)
    {
        for(auto u = undefined_table.begin(); u != undefined_table.end();)
        {
            if(0 == *u % prime_table[p])
            {
                u = undefined_table.erase(u);
            }
            else
            {
                ++u;
            }
        }

        if(!undefined_table.empty())
        {            
            prime_table.push_back(*undefined_table.begin());
            undefined_table.erase(undefined_table.begin());
            if(sn <= prime_table.back())
            {
                break;
            }
        }
    }
    prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
}

std::array<std::size_t, 1000000> prime_acc = {{0, 0}};

void make_prime_acc()
{
    std::size_t acc_found = 1;
    for(auto p = prime_table.begin(); p != prime_table.end(); ++p)
    {
        std::fill_n(prime_acc.begin() + acc_found + 1, *p - acc_found - 1, prime_acc[acc_found]);
        acc_found = *p;
        prime_acc[acc_found] = prime_acc[acc_found - 1] + 1;
    }
    std::fill(prime_acc.begin() + acc_found + 1, prime_acc.end(), prime_acc[acc_found]);
}

int main()
{
    make_prime_table();
    make_prime_acc();

    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_acc[n] << std::endl;
    }
}

C++: #include <iostream>
using namespace std;
#define x 1000000
int main(){
	bool q[x];
	for(int i=2;i<x;i++) q[i] = true;
	for(int i=2;i<x;i++) if(q[i]) for(int j=2;j<=x/i;j++) q[i*j] = false;
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=2;i<x;i++) if(q[i]) a++;
		cout << a << endl;
	}
}

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

int main(){
	int  n,i,j,sqrtn,sum;
	while(scanf("%d",&n)!=EOF){
		sum=(n-1)/2;
		for(i=3;i<=n;i+=2){
			sqrtn=(int)sqrt(i);
			for(j=1;j*2+1<sqrtn;j++){
				if(i%(j*2+1)==0){
					sum--;
					break;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

C++: #include<stdio.h>
#define size 1000000
int a[size],c[size];
void seive()   {    int i,j;
    //for(i=0;i<size;i++)    a[i]=1;    a[0]=a[1]=0;
    for(i=4;i<size;i+=2)     a[i]=1;
    for(i=3;i*i<size;i+=2)   {
        if(!a[i])   {
            for(j=i*i;j<size;j+=2*i)
                a[j]=1;  }   }    }

int main()
{
    seive();
    int i,n=0,x;
    for(i=2;i<size;i++)
    {
        if(!a[i])
        {
            n++;
        }
        c[i]=n;
    }
    while(scanf("%d",&x)==1)
    {
        printf("%d\n",c[x]);
    }
    return 0;
}

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

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList,primeList;
		for(int i=2;i<=NUM;++i){
			numList.push_back(i);
		}
	
		for(int i=numList.front();i<std::sqrt(NUM);i=numList.front()){
			primeList.push_back(i);
			numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
		}
		int cnt=numList.size()+primeList.size();	
		std::printf("%d\n",cnt);

		}
	return 0;
}

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

int main() {
  const int N = 1000000;
  vector<bool> prime(N, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i*i < N; ++i) {
    if (!prime[i]) { continue; }
    for (int j = i*i; j < N; j += i) {
      prime[j] = false;
    }
  }
  vector<int> ans(N);
  for (int i = 1; i < N; ++i) {
    ans[i] = ans[i - 1] + prime[i];
  }
  int n;
  while (cin >> n) {
    cout << ans[n] << endl;
  }
}

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

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	static bool prim[1000010]; rep(i,1000010)prim[i]=true;
	static int ans[1000010];
	ans[1]=0;
	
	int i=2;
	for(;i*i<=1000000;i++){
		ans[i]=ans[i-1];
		if(prim[i]){
			ans[i]++;
			for(int j=i*i;j<=1000000;j+=i){
				prim[j]=false;
			}
		}
	}
	for(;i<=1000000;i++){
		ans[i]=ans[i-1];
		if(prim[i])ans[i]++;
	}
	
	int n;
	while(~scanf("%d",&n))printf("%d\n",ans[n]);
}