Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

using namespace std;

int main()
{
	int n;
	int count;
	while (1)
	{
		cin >> n;
		if (cin.fail()) break;

		bool *isPrime;
		isPrime = new bool[n + 1];
		memset(isPrime, true, sizeof(bool) * (n + 1));
		isPrime[0] = isPrime[1] = false;
		
		count = 0;
		for (int i = 2; i <= n;++i)
		{
			while (isPrime[i] != true)
			{
				++i;
				if (i > n) break;
			}

			for (int j = i + i; j <= n; j += i)
			{
				isPrime[j] = false;
			}
		}
		for (int i = 0; i <= n; ++i)
		{
			if (isPrime[i] == true)
				++count;
		}
		cout << count << endl;
		delete[] isPrime;
	}
	return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
const int Max=10000000;
bool prime[Max];
int main(void){
    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 << "\n";
    }
    return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int flg[1000000];
int main(void)
{
	int n,i,j,cnt;
	while(scanf("%d",&n)!=EOF){
		for(i=2;i<=n;i++) flg[i]=1;
		for(i=2;i*i<=n;i++){
			if(flg[i]==1){
				for(j=2;i*j<=n;j++){
					flg[i*j]=0;
				}
			}
		}
		cnt=0;
		for(i=2;i<=n;i++){
			if(flg[i]==1) cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> v;
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int a,b,c=0;
	while(scanf("%d",&a)!=EOF){
		for (int A=2;A<=a;A++){
			for (int B=2;B<=A;B++){
				b=A%B;
				if (A==B){
					c++;
					break;
				}
				if (b==0) break;
			}
		}
		cout<<c<<endl;
		c=0;
	}
	return 0;
}

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

void count_Prime(int n);
int IsPrime(int num);


int main()
{
	int Data = 0;
	while (cin >> Data)
	{
		count_Prime(Data);
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 2; i < n; ++i)
	{
		counter += IsPrime(i);		
	}

	cout << counter << endl;

}

int IsPrime(int num)
{
	if (num < 2) return 0;
	else if (num == 2) return 1;
	else if (num % 2 == 0) return 0; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return 0;
		}
	}

	// ?´???°??§??????
	return 1;
}

C++: #include <iostream>
 
 int main() {
     int n;
     while (std::cin >> n) {
        int primes = 0; // n以下の素数の数
         for (int i = 2; i <= n; i++) {
               bool flag = false; // はずれの目印
               for (int j = 2; j < i; j++)
                 if (!(i % j)) {
                     flag = true;
                    break;
                  }
              if (!flag)
                  primes++;
          }
          std::cout << primes << std::endl;
      }
  }

C++: 
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		while(true){
			Scanner sc=new Scanner(System.in);
			int INF=1000;
			int cnt=0;
			int n=sc.nextInt();
			int[] prime=new int[n+1];
			for(int i=0;i<=n;i++){
				prime[i]=INF;
			}
			for(int i=2;i<=n;i++){
				if(prime[i]==INF&&n%i==0){
					prime[i]=0;
					cnt++;
					for(int j=2;j*i<=n;j++){
						prime[j*i]=1;
					}
				}
			}
sc.close();
			System.out.println(cnt);
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  int a,t[1000000],u[1000000];
  for(int i=0;i<1000000;i++){
    t[i]=1;
  }
  t[0]=t[1]=u[0]=u[1]=0;
  for(int i=2;i<=1000000;i++){
    if(t[i]==1){
      for(int j=i+i;j<1000000;j+=i)t[j]=0;
      u[i]=u[i-1]+1;
    }else{
      u[i]=u[i-1];
    }
  }
  while(cin>>a){
    cout<<u[a]<<endl;
  }
  return 0;
}

C++: // 6/2
// 2-6-4. 素数のこすう
// エラトステネスの篩
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

// const int MAX_N = 1000000;

vector<int> prime;  // i番目の素数
vector<bool> is_prime;  // iが素数かどうか

void sieve(int n) {
    // 一旦全ての数字を素数に。
    prime.resize(n, 0);
    is_prime.resize(n + 1, true);

    // 0, 1は素数では無い。
    is_prime[0] = is_prime[1] = false;

    int p = 0;

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

int main() {
    sieve(1e6);

    int n;
    vector<int> ans;

    while (cin >> n) {
        int an = 0;
        rep(i, n + 1) {
            if (is_prime[i]) an++;
        }
        ans.push_back(an);
    }

    for (auto a : ans) cout << a << endl;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int n;
    int prime[100000];
    long long ptr = 0;

    prime[ptr++] = 2;
    prime[ptr++] = 3;

    while (cin >> n) {
        if (n <= 1) {
            cout << "0\n";
            continue;
        }
        else if (n == 2) {
            cout << "1\n";
            continue;
        }
        else if (n == 3) {
            cout << "2\n";
            continue;
        }

        int count = 2;        
        for (int i = 5; i <= n; i += 2) {
            bool flag = false;
            for (int j = 1; prime[j] * prime[j] <= i; j++) {
                if (!(i % prime[j])) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                prime[ptr++] = i;
                count++;
            }
        }
        cout << count << "\n";
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(void){
  int n;
while(cin>>n){
  vector<bool> nature(n,true);
  nature[0]=nature[1]=false;
  for(int i=0;i*i<=n;i++){
if(nature[i]){
  for(int j=2;j<=n/i;j++)
  nature[i*j]=false;
}
  }
int count=0;
for(int i=0;i<=n;i++)
if(nature[i])
count++;
cout<<count<<endl;
}
return 0;
}