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 <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool prime(int n)
{
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
    int c,i,p=0;
    int in[30],out[30];
    while(scanf("%d",&in[p])!=EOF)
    {
        c=0;
        for(i=2;i<=in[p];i++)
        {
            if(prime(i))
                c++;
        }
        out[p] = c;
        p++;
    }
    for(i=0;i<p;i++)
        cout<<out[i]<<endl;
    return 0;
}

C++: #include<iostream>
using namespace std;
int main() {
	int a;
	int sum;
	while (cin >> a){
		sum = 0;
		for (int i = 0; i < a; i++){
			int y = 0;
			int l = i + 1;
			for (int i = 1; i != l+1; i++){
				if (l % i == 0) {
					y++;
				}
			}
			if (y == 2)sum++;
		}
		cout << sum << endl;
	}
}

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

int main(){
	const int MAX_n = 1000000;
	int n;
	bool prime[MAX_n];
	int res;
	
	for(int i = 0; i < MAX_n; i++) prime[i] = false;
	
	for(int i = 2; i < MAX_n; i++){
		if(!prime[i]){
			//printf("%d\n", i);
			for(int j = i + i; j < MAX_n; j += i){
				prime[j] = true;
				
			}
		}
	}
	
	//for(int i = 0; i < MAX_n; i++) if(prime[i]) printf("%d\n", i);
	
	while((scanf("%d", &n)) != EOF){
		res = 0;
		
		for(int i = 2; i <= n; i++){
			if(!prime[i]){ res++; }
		}
		
		printf("%d\n", res);
	}
	
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main(){

	vector<bool> used(1000000);
	set<ll> prime;
	
	REP(i, 2, 1000000){
		if(!used[i]) prime.insert(i);
		for(int j = 1; i * j < 1000000; j++){
			used[i*j] = true;
		}
	}
	
	int n;
	while(cin >> n){
		auto it = upper_bound(prime.begin(), prime.end(), n);
		cout << distance(prime.begin(), it) << endl;
	}
	
	
	return 0;
}

C++: <?php
$max=1000000;
$maxR=floor(sqrt($max));

$ch=[0,0,1,1];

for($i=4;$i<$max;$i+=2){
  $ch[]=0;$ch[]=1;
}

for($i=3;$i<$maxR;$i+=2){
  if($ch[$i]){
    for($j=$i+$i;$j<$max;$j+=$i){
      $ch[$j]=0;
    }
  }
}

for($i=3;$i<$max;$i++){
  $ch[$i]+=$ch[$i-1];
}

while(fscanf(STDIN,"%d",$n)){
  printf("%d\n",$ch[$n]);
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

bool isPrimes[1000000];

int main()
{
	int res = 0;
	int n;
	scanf("%d", &n);
	for (int i = 0; i <= n; ++i)
		isPrimes[i] = true;
	isPrimes[0] = isPrimes[1] = false;
	for (int i = 2; i <= n; ++i)
	{
		if (isPrimes[i])
		{
			for (int j = i*2; j <= n; j += i)
				isPrimes[j] = false;
			++res;
		}
	}
	printf("%d\n", res);

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;
const int maxx = 2000000;
bool is_prime[maxx];
int prime[maxx];
int a,cnt = 0;
int main()
{
    memset(is_prime,true,sizeof is_prime);
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i * i < maxx; i ++ )
    {
        if(is_prime[i])
        {
            prime[cnt++]=i;
            for(int j = i*2;j < maxx; j+=i ) is_prime[j] = false;
        }
    }
    while(scanf("%d",&a)!=EOF)
    {
        int k = upper_bound(prime,prime+cnt,a) - prime;
        printf("%d\n",k);

    }

    return 0;
}

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

void sieve(int n, vector<int> &primes)
{
    vector<bool> v(n + 1, true);

    // check
    for (int i = 2, end = sqrt(n); i <= end; i++) {
        if (!v[i] || !(i & 1))
            continue;
        for (int j = i + i; j <= n; j += i)
            v[j] = false;
    }

    primes.push_back(2);
    for (int i = 3; i <= n; i += 2)
         if (v[i])
            primes.push_back(i);
}

int main()
{
    vector<int> primes;
    vector<int> inputs;
    int i;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        for (i = 0; i < primes.size(); i++) // find
            if (primes[i] == x) {
                i++;
                break;
            } else if (primes[i] > x)
                break;
        cout << i << endl;
    }

    return 0;
}