Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: #include <iostream>

int PrimeNumberCount(int*, int);

const unsigned int MAX_NATURAL_NUMBER = 1000000;

int main(){
	int BoolPrimeNumber[MAX_NATURAL_NUMBER] = { 1, 1 };
	int NaturalNumber;
	for (int i = 2; i * i < MAX_NATURAL_NUMBER; ++i){
		if (!BoolPrimeNumber[i]){
			for (int j = i * 2; j < MAX_NATURAL_NUMBER; j += i){
				BoolPrimeNumber[j] = 1;
			}
		}
	}
	while (std::cin >> NaturalNumber){
		std::cout << PrimeNumberCount(BoolPrimeNumber, NaturalNumber) << std::endl;
	}
}

int PrimeNumberCount(int* BoolPrimeNumber, int NaturalNumber){
	int count = 0;
	for (int i = 2; i < NaturalNumber + 1; ++i){
		if (BoolPrimeNumber[i] == 0){
			++count;
		}
	}
	return count;
}

C++: #include <stdio.h>
#define false 0
#define true 1
 
int main(){
  char is_prime[1000000];
  int n;
  int n_prime[1000000];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<1000000;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<1000000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<1000000;j=j+i){
        is_prime[j] = false;
      }
    }
  }
  int cnt = 0;
  for(int i=0;i<1000000;i++){
    if(is_prime[i]){
      cnt++;
    }
    n_prime[i] = cnt;
  }
 
  while(scanf("%d",&n) != EOF){
    printf("%d\n",n_prime[n]);
  }
 
  return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		//result[cnt] = count_prime_number(n);
		
		int rtn = 0;

		//2だけ個別チェック
		if (n >= 2){
			rtn++;
		}

		for (int i = 3; i <= n; i += 2)
		{
			bool is_prime_num = true;
			for (int j = 3; j <= sqrt(i); j += 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
			{
				if (i % j == 0)
				{
					is_prime_num = false;
					break;
				}
			}

			if (is_prime_num){
				rtn++;

				//デバッグ
				//std::cout << i << std::endl;
			}
		}

		result[cnt] = rtn;

		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

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

/*
10
3
11

4
2
5
*/

const int MAX_N = 1e6 + 10;
int N = 0;

bool is_prime[MAX_N + 1];
void sieve(int n) {
    fill(is_prime, is_prime + n + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (is_prime[i]) {
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

void solve() {
    int res = 0;
    for (int i = 2; i <= N; i++) {
        if (is_prime[i]) {
            res++;
        }
    }

    printf("%d\n", res);
}

int main() {
    sieve(MAX_N);
    while (scanf("%d", &N) != EOF) {
        solve();
    }

    return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  vector<int> result;
  while (cin >> n) {
    vector<int> nums;
    nums.reserve(n+1);
    for (int i = 0; i <= n; i++)
      nums.push_back(i);

    for (int i = 2; i <= n; i++) {
      if (nums[i] == 0)
        continue;
      int hoge = nums[i];
      for (int j = i+1; j <= n; j++) {
        if (nums[j] == 0)
          continue;
        else if (nums[j] % hoge == 0)
          nums[j] = 0;
      }
    }

    int piyo = 0;
    for (int i = 2; i <= n; i++)
      if (nums[i])
        piyo++;
    result.push_back(piyo);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

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

bool isPrime(int x){
	if(x == 0 || x == 1) return false;
	for(int i=2;i*i<=x;i++){
		if(x % i == 0) return false;
	}
	return true;
}

int main(void){
	int n;
	int ans = 0;
	
	while(cin>>n){
		for(int i=2;i<=n;i++){
			if(isPrime(i)) ans++;
		}
		printf("%d\n",ans);
	}

	return 0;
}

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

int main(){
    bool prime[1000000];
    prime[0] = prime[1] = false;
    
    int n, cnt;
    
    while(cin >> n){
        for(int i = 2;i <= n;i++){
            prime[i] = true;
        }
        cnt = 0;
        
        for(int i = 2;i <= sqrt(n);i++){
            if(prime[i]){
                for(int j = 2*i;j<= n;j++){
                    if(j%i == 0){
                        prime[j] = false;
                    }
                }
            }
        }
        
        for(int i = 2;i <= n;i++){
            if(prime[i]){
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
int p(long x)
{
    long i,j=sqrt(x),k=1;
    for(i=2;i<=(j);i++)
    {
        if(x%i==0){
            k=0;
            //return k;
        break;

        }
    }
    if(k==1)return 1;
    else return 2;
}
using namespace std;
int main()
{
    double a,b,c,i,n,s=0;
   // i=1;

    //while(i){
       // if(i>=30)break;
        cin>>n;
        s=0;
    //a=sqrt(n);
    for(i=2;i<=n;i++)
    {
        if(p(i)==1){s++;}
    }

    cout<<s<<endl;
  //  i++;
    //}


    return 0;
}

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

int main() {
	int n,yakusuu,sosuu;
	for (int x = 0; x < 30;x++) {
		cin >> n;
		sosuu = 0;
		for (int i = 1; i <= n; i++) {
			yakusuu = 0;
			for (int j = 1; j <= i; j++){
				if (i%j == 0)yakusuu++;
			}
			if (yakusuu == 2)sosuu++;
		}
		cout << sosuu << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool eratosthenes[1000000];

int main()
{
	for (int i=0; i<1000000; i++) eratosthenes[i] = true;		
	eratosthenes[0] = eratosthenes[1] = false;
	
		for (int i=2; i<1000000; i++) {
		if (!eratosthenes[i]) continue;
		for (int j=2; i*j<1000000; j++) eratosthenes[i*j] = false;
	}
	
	int n;
	while (cin >> n) {
	
		int count = 0;
		for (int i=0; i<=n; i++) {
			if(eratosthenes[i]) count++;
		}
		
		cout << count << endl;
	}
	
	return 0;
}