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>
using namespace std;
#define REP(i,n) for(unsigned int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define MAX 1000001
 
bool N[MAX] = {};
 
int M[MAX] = {};
 
void SoE()
{
    REP(i, MAX)N[i] = true;
 
    N[1] = true;
    for (unsigned int i = 2; i*i <= MAX; i++)
    {
        for (unsigned int j = i+i; j < MAX; j += i)
        {
            N[j] = false;
        }
    }
}
 
void Count()
{
    M[1] = 0;
    FOR(i, 2, MAX - 1)
    {
        int add = 0;
        if (N[i] == true)
        {
            add = 1;
        }
        M[i] = M[i - 1] + add;
    }
}
 
int main()
{
    SoE();
    Count();
    int tmp;
    while (cin >> tmp)
    {
        cout << M[tmp] << endl;
    }
    return 0;
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n * 1.0); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	delete[] prime;
	return ct;
}

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