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

const int kMaxN = 1000000;

int main()
{
    vector<int> prime;
    prime.reserve(100000);
    prime.push_back(2);
    prime.push_back(3);
    prime.push_back(5);
    prime.push_back(7);
    for (int i = 9; i <= kMaxN; i += 2){
        bool ok = true;
        for (int j = 0, j_max = prime.size(); j < j_max; ++j){
            if (i % prime[j] == 0){
                ok = false;
                break;
            }
        }
        if (ok) prime.push_back(i);
    }

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

C++: import java.util.Scanner;

public class Main
{

	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int count=0;
		for (int i=2; i<=n; i++)
		{
			if(prim(i))
				count++;
		}		
		System.out.println(count);
	}

	public static boolean prim(int a)
	{
		if(a<2)
			return false;
		else if (a==2)
			return true;
		
		for(int j = 2; j<a; j++)
		{
			if(a%j==0)
				return false;
		}
		return true;
	}
}

C++: #include<stdio.h>

int	main(){
	int	i,	k,	x,	cnt[1000001],	data[1000000];
	cnt[0]	=	0;
	data[0]	=	0;
	data[1]	=	0;
	for(i	=	2;	i	<=	1000000;	i++){
		data[i]	=	1;
	}
	for(i	=	2;	i	*	i	<=	1000000;	i++){
		if(data[i]){
			for(k	=	2	*	i;	k	<=	1000000;	k	+=	i){
				data[k]	=	0;
			}
		}
	}
	for(i	=	0;	i	<=	1000000;	i++){
		cnt[i	+	1]	=	cnt[i]	+	data[i];
	}
	while(1){
		scanf("%d",	&x);
		if(x	==	0)break;
		printf("%d\n",	cnt[x]);
	}
	return	0;
}

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

using namespace std;
vector<int> prime;

int calc(int);

int main(){
    int n;
    prime.push_back(2);
    while(-1!=scanf("%d", &n)){
        cout << calc(n) << endl;
    }
    return 0;
}

int calc(int n){
    int lastPrime = prime[prime.size()-1];
    if(n > lastPrime){
        for(int i=lastPrime; i<=n; i++){
            bool isPrime = true;
            for(int j=0; j<prime.size(); j++){
                int checkPrime = prime[j];
                if(i%checkPrime==0){
                    isPrime = false;
                    continue;
                }
            }
            if(isPrime) prime.push_back(i);
        }
        return prime.size();
    }else{
        for(int i=0; i<prime.size(); i++){
            if(prime[i]>=n){
                return i;
            }
        }
    }
    return -1;
}

C++: #include <iostream>

int main(void)
{
	int32_t n = 0;
	int32_t count = 0;
	int32_t count2 = 0;
	bool flag = false;

	while (std::cin >> n)
	{
		count2 = 0;
		for (int i = 2; i <= n; i++)
		{
			flag = false;
			for (int j = i-1; j > 1; j--)
			{
				if (i % j == 0)
				{
					flag = true;
					break;
				}
			}
			if (flag == false)
			{
				count2++;
			}
		}
		std::cout << count2 << std::endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    double he=0;
    while(cin>>n){
        he=sqrt(n);
        int ser[n+1];
        for(int i=2;i<=n;i++)ser[i]=1;
        for(int i=2;i<he;i++)if(ser[i]==1)for(int j=2;j*i<=n;j++)ser[i*j]=0;
        for(int i=2;i<=n;i++)if(ser[i]==1)co++;
        cout<<co<<endl;
        co=0;
    }
}

C++: #include    <iostream>
 
using namespace std;
 
bool F[1000003] = { false };
int DP[80000] = { 0 };
void prepa_Prime();
int count_Prime(int);
 
int main() {
    int n;

    prepa_Prime();
    while (cin >> n) {
        cout << count_Prime(n) << endl;;
    }
    return 0;
}
 
void prepa_Prime() {
    int i, c = 2;

    F[0] = F[1] = true;
    DP[0] = 1;

    DP[1] = 2;
    for (i = 4; i <= 1000003; i += 2) { F[i] = true; }
    
    for (i = 3; i <= 1000003; i += 2) {
        if (F[i] == false) {
            DP[c++] = i;
            for (int j = i * 2; j <= 1000003; j += i) {
                F[j] = true;
            }
        }
    }
}

int count_Prime(int n) {
    int i = 0;
    for (i; DP[i + 1] <= n; i++) {}
    return i;
}

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


int prime[100000]={0};
int k=1;
void
 makeprime(int n)
{
    prime[0]=2;
    for (int i = 3; i < n; i++)
    {
        double temp = sqrt(i);
        for (int j = 0;; j++)
        {
            if (i % prime[j] == 0)
            {
                break; //this is no prime.
            }
            if (temp < prime[j])
            {
                prime[k++]=i;
                break;
            }
        }
    }
}

int main()
{
    makeprime(999999);
    
    int n;
    int ans=0,i;
    while(cin>>n){
        ans=0;
        i=0;
        while(true){
            if(prime[i]<=n){
                ans++;
            }
            if(n<prime[i]){
                break;
            }
            i++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
int a[1000000]{};
bool b[1000000]{};
a[1]=0;
int s=0;
for(int c=2;c<1000000;c++){
	if(!b[c]){
		s++;
		for(int d=c*2;c<1000000;d+=c)b[d]=true;
	}
	a[c]=s;
}
int k;
while(cin>>k){
	printf("%d\n",a[k]);
}
}

C++: #include <iostream>
using namespace std;
const int Max = 10000000;
bool prime[Max];
int main() {
    int in;
    for(int i=0; i<Max; i++) prime[i] = true;
    prime[1] = false;
    for(int i=2; i<Max; i++) {
        if(prime[i]) {
            for(int s=i*2; s<=Max; s+=i) prime[s] = false;
        }
    }
    while(cin >> in) {
        int cnt = 0;
        for(int i=1; i<=in; i++) {
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#define N 999999

using namespace std;

int main(){
  int i, j, n, isFound, count;
  vector<int> data;

  data.push_back(2);
  data.push_back(3);
  for(i=5; i<=N; i+=2){
    for(j=1, isFound=0; data[j]<=sqrt(i); ++j){
      if(i%data[j] == 0){
	isFound = 1;
	break;
      }
    }
    if(isFound == 0) data.push_back(i);
  }

  while(cin >> n){
    for(i=0; i<data.size(); ++i){
      if(n < data[i]) break;
    }
    cout << i << endl;
  }

  return 0;
}

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

int* PrimeCount();

int main()
{
	int n;

	int* a = PrimeCount();

	while (cin >> n) {
		cout << a[n] << endl;
	}

	return 0;
}

int* PrimeCount()
{
	//最大探索値 999999まで
	const int MAX = 1000000;

	//配列全てに1
	array<int, MAX> search;

	for (int i = 2; i < MAX; i++) {
		search[i] = 1;
	}

	for (int i = 2; i < MAX; i++)
	{
		//素数
		if (search[i] == 1)
		{
			//素数の倍数に0
			for (int j = i * 2; j < MAX; j += i)
			{
				search[j] = 0;
			}
		}
	}

	//任意の数字以下での素数の数
	for (int i = 1; i < MAX; i++)
	{
		//1が入ってるとカウントも+1
		search[i] += search[i - 1];
	}

	return &search[0];
}