Go: package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	//"math"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		fmt.Println(calc(n))
	}
}

func calc(n int)int{
	// エラトステネスで数え上げる
	// 最初から999999まで用意しておいて入力のたびO(1)で出すのとどっちが速いのかはわからん
	eratos := make([]bool, n+1)
	c := 0
	for i:=2; i<len(eratos); i++{
		if eratos[i] == false{
			c++
			for j:=i*i; j<len(eratos); j+=i{
				eratos[j]=true
			}
		}
	}
	return c
}

func next()string{
	return sc.Text()
}

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}

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


int main(void){

	
	int n,count;
	

	while (cin >> n){
		vector <int> list(n+1, 0);

		for (int i = 2; i < n+1; i++){
			list[i] = i;
		}//???????????????????????°???????????????

		//??????????????§?¨???????????????????????????\??£???????????????????´???°?¢????
		for (int i = 2; i < sqrt(n)+1; i++){
			//??????????????\??£??????????´???°???????????????????????????
			if (list[i] == i){//0???????????¢?????§?????°???????????°????????§??????
				//?????????????????????????????§????????°????´???°??§??????
				//????????°????????°???0?????£??\??????
				for (int j = i * 2; j < n+1; j += i){
					list[j] = 0;
				}					
			}
			
				
			}

		count = 0;
		for (int i = 2; i < n+1; i++){
		
			if (list[i] == i){ count++; }

		}cout << count << endl;
		
		
		}//while?????????



	return 0;
}

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

using namespace std;

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

int countPrime(int x)
{
	int count = 0;
	for (int i = 2; i <= x; i++)
	{
		if (isPrime(i))
		{
			count++;
		}
	}
	return count;
}

int main()
{
	int n;
	while (cin >> n, !cin.eof())
	{
		cout << countPrime(n) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
			flag=false;
			break;//素数でない時点で打ち切り
			}
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		sosu[i]=(flag)? cnt++ : cnt;		
	}
	//for(int i=0;i<30;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

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

using namespace std;


int main() {
	int n;
	bool p[1000000];

	p[0] = 0;
	p[1] = 0;

	for(int i = 2; i <= 999999; i++) {
		p[i] = true;
	}

	for(int i = 2; i * i <= 999999; i++) {
		for(int j = 2; j * i <= 999999; j++) {
			p[j * i] = false;
		}
	}

	while(cin >> n) {
		int count = 0;
		for(int i = 2; i <= n; i++) {
			if(p[i] == true) {
				count++;
			}
		}

		cout << count << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <set>
#include <cmath>
std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 1000000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i && it != PRIMES.end()) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
	if(n % i == 0) return false;
  }
  return true;
}
*/

bool isPrime(int x) {
  if (x == 2) return true;

  else if (x < 2 || x % 2 == 0) return false;

  int i = 3;
  while(i <= sqrt(x)) {
	if(x % i == 0) return false;
	i += 2;
  }
  return true;
}

int main() {
  int n;
  while(cin >> n) {
	int cnt = 0;
	for(int j = 2; j <= n; ++j) {
	  if(isPrime(j)) cnt ++;
	}
	cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long i64;


template<i64 N> struct prime_numbers{
  set<i64> primes;
  bool p[N+1];
  
  constexpr prime_numbers<N>() : primes(), p() {
    p[0] = p[1] = true;
    for(i64 i=2; i<=N; i++) {
      if(p[i]) continue;
      if(i*i<=N) {
        for(i64 j=i; i*j<=N; j++) {
          p[i*j] = true;
        }
      }
      primes.insert(i);
    }
  }
  
  bool is_prime(i64 n) {
    return primes.find(n) != primes.end();
  }
};


int main(){
  i64 n;
  prime_numbers<1000000LL> ps;
  while(cin >> n) {
    int res = 0;
    for(int i=1; i<=n; i++) if(ps.is_prime(i)) res++;
    cout << res << endl;
  }
  
}

C++: #include <iostream>

using namespace std;

#define MAX_N (1000000)

bool is_prime[MAX_N];
int sum[MAX_N + 1];

int main()
{
    int n;
    
    for (int i = 0; i < MAX_N; i++){
        is_prime[i] = true;
    }
    
    is_prime[0] = false;
    is_prime[1] = false;
    
    for (int i = 4; i < MAX_N; i += 2){
        is_prime[i] = false;
    }
    
    for (int i = 3; i * i < MAX_N; i += 2){
        for (int j = i + i; j < MAX_N; j += i){
            is_prime[j] = false;
        }
    }
    
    sum[0] = 0;
    for (int i = 0; i < MAX_N; i++){
        sum[i + 1] = sum[i] + is_prime[i];
    }
    
    while (cin >> n){
        cout << sum[n + 1] << endl;
    }
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define MAX_SIZE 1000100
#define N 999999
int preme[MAX_SIZE];

int main(int argc, char *argv[]) {
	int a = 999999;
	cout << a << endl;
	for(int i = 0; i < MAX_SIZE; i++)
		if(i % 2)
			preme[i] = 1;
		else {
			preme[i] = 0;
		}
	preme[2] = 1;
	preme[1] = 0;
	for(int i = 3; i <= 999999; i += 2) {
		if(preme[i]) {
			for(int j = i + i; j <= 999999; j += i)
				preme[j] = 0;
		}
			
	}
	//freopen("data.txt", "r", stdin);
	//freopen("data_test2.txt", "w", stdout);
	int n;
	while(cin >> n){
		int count = 0;
		for(int i = 1; i <= n; i++)
			if(preme[i])
				count++;
		cout << count << endl;
	}
		
}

C++: #include <iostream>

using namespace std;

bool is_prime(int n) {
        if (n < 2) {
                return false;
        }

        int max = n / 2;
        int i;
        for (i=2; i < max; i++) {
                if (n % i == 0) {
                        return false;
                }
        }

        return true;
}

int number_of_primes_under(int n) {
        if (n < 2) {
                return 0;
        }

        int count = 1;
        int i;
        for (i=3; i <= n; i = i + 2) {
                if (is_prime(i)) {
                        count++;
                }
        }

        return count;
}
int main(void) {
        int n;
        while(cin >> n) {
                cout << number_of_primes_under(n);
                cout << endl;
        }

        return 0;
}

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

using namespace std;

int p[1000000];
int cnt[1000000];

int main()
{
  fill(p, p + 1000000, 1);
  p[0] = p[1] = 0;
  for(int i=2;i<1000000;i++)
    for(int j=i*2;j<1000000;j+=i)
      p[j] = 0;

  for(int i=1;i<1000000;i++)
    cnt[i] = cnt[i-1] + p[i];

  int n;
  while(scanf("%d", &n) != -1)
    printf("%d\n", cnt[n]);

  return 0;
}