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 <cstdio>
#include <iostream>

using namespace std;

const int MAX_N = 1000000;

int N;

int len;
bool isPrime[MAX_N];
int num[MAX_N];				//the number of prime less than i

void sieve(){
	//init
	fill(isPrime, isPrime + MAX_N, true);
	isPrime[0] = isPrime[1] = false;
	num[0] = num[1] = 0;
	for(int i = 2; i < MAX_N; i ++){
		if(isPrime[i]){
			num[i] = num[i - 1] + 1;
			for(int j = 2 * i; j < MAX_N; j += i)
				isPrime[j] = false;
		}
		else{
			num[i] = num[i - 1];
		}
	}
}

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

	sieve();
	while(scanf("%d", &N) != EOF){
		printf("%d\n", num[N]);
	}

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

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

int main(){
int n;
while(~scanf("%d",&n)){
int* table =  new int[n+1];
fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i*i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

C++: #include <stdio.h>

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    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;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

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

#define N_MAX 1000000

using namespace std;

int main(void)
{
	int n = 0;
	bool isNotPrime[N_MAX] = { false };
	
	isNotPrime[0] = true;
	int rootN = sqrt(N_MAX);
	for(int i = 2; i <= rootN; i++){
		for(int j = 2 * i; j < N_MAX; j += i){
			isNotPrime[j - 1] = true;
		}
	}
	
	while(cin >> n){
		//素数の数をカウント
		int cnt = 0;
		for(int i = 0; i < n; i++){
			if(!isNotPrime[i]){
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}

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

int main(){
	int n;
	int a=0;
	while(cin >> n){
		for(int i = 0; i < n; ++i){
			for(int j = 2; j <= i; ++j){

				if(i%j == 0){
				if(i==j){
					++a;
				}else{
					break;
				}
				}
		}
	
	}
		cout << a << '\n';
}
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]==true){
        for(long long int  = (long long int)i*i;j<MAX;j=j*j){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
    int X,ans,count;
    bool num[1000001]={};
    for(int i=2;i<=1000000;i++){
        if(!num[i]) 
        for(int j=i*2;j<=1000000;j+=i)  num[i] = true;
    }
    while(cin >> X)
    {
        count = 0;
        for(int i=2;i<=X;i++){
            if(!num[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

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

using namespace std;

vector<bool> prime(1000010, 1);

signed main(){
    prime[0] = 0; prime[1] = 0; prime[2] = ( const ) 1;
    int ret = 0;
    int n; scanf( "%d", &n );
    for( int i = 2; i * i <= n; i++ ){
        if( prime[i] ){
            for( int j = 1; ( j + 1 ) * i <= n; j++ ){
                prime[i * ( j + 1 )] = 0;
            }
        }
    }
    for( int i = 0; i <= n; i++ )
    {
        if( prime[i] )
        {
            ret++;
        }
    }
    printf( "%d\n", ret );
    return 0;
}

C++: #include <iostream>
using namespace std;
int n;
#define MAX_N 1000000

int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数

// n以下の素数の数を返す
int sieve(int n) {
    int p = 0;
    for(int i=0;i<=n;i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i=2; i<=n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for(int j=2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

main() {
    sieve(MAX_N);
    while(cin>>n) {
        int ans=0;
        for(int i=2;i<=n;i++) {
            if(is_prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

C++: #include<iostream>
#define MAX_N 1000000
using namespace std;

static bool prime[MAX_N];
 static int num[MAX_N] = { 0 };

void ini()
{
	for (int i = 2; i < MAX_N; i++)
		prime[i] = true;
	for (int i = 2; i < MAX_N; i++)
	{
		if (!prime[i])
		{
			num[i] = num[i - 1] + prime[i];
			continue;
		}
		else
		{
			for (int j = i * 2; j < MAX_N; j += i)
			{
				if (prime[j] && j%i == 0)
					prime[j] = false;
			}
		}
		num[i] = num[i - 1] + prime[i];
	}
}

void solve()
{
	int n;
	while (cin >> n)
		cout << num[n] << endl;
}

int main()
{
	ini();
	solve();
	return 0;
}

C++: #include <cstdio>
int d[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i])continue;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	for(i=2;i<=999999;i++) {
		if(!d[i])r++;
		d[i]=r;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",d[n]);
	}
}

C++: #include<iostream>
int main(){
	for(int m,n,p;!(std::cin>>n).eof();){
		if(n<3)
			p=!(n-2);
		else for(m=3,p=1;m<=n;m+=2){
			p++;
			if(m<2)
				p--;
			else{
				for(int i=3;i*i<=m;i+=2)
					if(m%i==0){p--;break;}
			}
		}
		printf("%d\n",p);
	}
}

C++: 
def generate (n)
    $P = Array.new(n, false)
    i = 3
    until i > n
        $P[i] = true
        i += 2
    end
    i = 3
    $P[2] = true
    until i > n
        if ! $P[i]
            i += 2
            next
        end
        j = i + i
        until j > n do
            $P[j] = false
            j += i
        end
        i += 2
    end
end

def is_prime (n)
    return $P[n] ? 1 : 0
end

def solve (n)
    return ->() {
        res = 0
        (n+1).times {|v| res += is_prime(v) }
        res
    }.call
end

generate 1000000 
while s = gets do
    n = s.to_i
    p solve n
end

C++: #include<stdio.h>

int main(void)
{
	int d=2,i,j,s[10000],x;

	while((scanf("%d",d))!=EOF)
	{
		for(i=0;i<=d;i++){
			s[i]=1;}
		x=0;
		if(d<=1){
			printf("%d\n",0);
		}
		else
		{
			for(i=2;i<=d/2;i++)
			{
			  if(s[i]!=0)
			  {
				for(j=i*2;j<d;j+=i)
				    s[j]=0;
			  }
			}
		for(i=0;i<=d;i++)
			x+=s[i];
		printf("%d\n",x);
		}
	}
  return 0;
}

C++: #include<iostream>
using namespace std;
#define N 1000000
bool p[1000000];
int main(){
  int n;

  for(int i=0;i<N;i++)p[i]=true;
  p[0]=p[1]=false;

  for(int i=0;i<=N/2;i++)
    if(p[i]==true)
      for(int j=i*2;j<N;j+=i)
	p[j]=false;

  while(cin>>n){
    int count=0;
    for(int i=0;i<=n;i++)
      if(p[i]==true)count++;
    cout<<count<<endl;
  }
  return 0;
}