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 n,i,c,k,t;
	while(scanf("%d",&n) != EOF){
	i = 0;
	for(c = 2; n >= c; c++){
		t = 0;
		for(k = 2; c/2 >= k; k++){
			if(c%k == 0){t =1;break;}
		}
		if(t == 0)i++;
	}

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

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int ans=0,math[1001000]={0};
    math[1]=1;
    for(int i=2;i<n+1;i++){
      int bell=i;
      if(math[i]==0){
	ans++;
	math[i]=1;
      }
      while(bell<=n){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      } 
    }
    cout << ans << endl;
  }
}

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

using namespace std;

int main()
{
	bool a[1000000];
	int n;
	
	fill(a, a+1000000, false);
	a[2] = true;
	for(int i = 3; i < 1000000; i+=2){
		bool f = true;
		for(int j = 3; j*j <= i; j+=2){
			if(i%j == 0){
				f = false;
				break;
			}
		}
		a[i] = f;
	}
	
	while(cin >> n){
		int c = 0;
		for(int i = 2; i <= n; i++){
			if(a[i]){
				c++;
			}
		}
		cout << c << endl;
	}
	
	return 0;
}

C++: using System;
using System.Collections;

class main
{
    static void Main(String[] args)
    {
        while (true)
        {
            string s = Console.ReadLine();           
            if (s != null)
            {
                int c = 0;
                int f = 0;
                int n = int.Parse(s);
                int r = (int)Math.Sqrt(n);
                ArrayList  p = new ArrayList();
                if (n > 1)
                {
                    for (int a = 2; a <= n; a++)
                    {
                        p.Add(a);
                    }
                    while (true)
                    {
                        f = (int)p[0];
                        c++;
                        for (int i = 0; i < n; i++)
                        {
                            p.Remove(f * i);
                        }
                        if (f > r)
                        {
                            break;
                        }
                    }
                    Console.WriteLine("{0}",c+p.Count);
                }
                if (n <= 1)
                {
                    Console.WriteLine(0);
                }
            }
            if (s == null)
            {
                break;
            }
        }
        Console.ReadKey();
    }
}

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;
}