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 <cmath>

const int LIMIT = 1000000;

void eratosthenes(int n, bool *primes);

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    bool primes[LIMIT];
    for (int i = 1; i < LIMIT; ++i)
        primes[i] = false;
    eratosthenes(LIMIT, primes);
    int num_of_primes[LIMIT] = {};
    for (int i = 1; i < LIMIT; ++i) {
        num_of_primes[i] = num_of_primes[i-1];
        if (primes[i])
            ++num_of_primes[i];
    }

    int n;
    while (std::cin >> n) {
        std::cout << num_of_primes[n] << std::endl;
    }
}

void eratosthenes(int n, bool *primes)
{
    primes[2] = true;
    int i = 3;
    double root_n = std::sqrt((double) n);
    while (i <= root_n) {
        if (n % i != 0) primes[i] = true;
        i += 2;
    }
}

C++: #include <iostream>

int main()
{
    bool *table = new bool[1000000];
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        memset(table, 1, sizeof(bool) * (n + 1));
        for (int i = 2; i * i <= n; ++i)
            for (int j = 2; i * j <= n; ++j)
                table[i * j] = false;

        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += table[i];
        std::cout << cnt << std::endl;
    }
    delete[] table;
}

C++: #include <iostream>
using namespace std;
const int MAX_N = 1000000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int eratos(int n)
{
	int p = 0;
	for (int i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	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()
{
	int n;
	while (cin >> n && n)
	{
		cout << eratos(n) << endl;
	}
	return 0;
}

C++: 
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		vector<int> sos;
		sos.emplace_back(2);
		int s = 1;
		for (int j = 2; j <= n; j++) {
			for (int i = 0; i < sos.size(); i++) {
				if (j%sos[i] == 0) {
					break;
				}
				if (i == sos.size()-1) {
					sos.emplace_back(j);
					s++;
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

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

int CountPrime(int N);
int CheckPrime(int N);
bool IsPrime(int num);

int main()
{
	int N;

	while (std::cin >> N)
	{
		std::cout << CountPrime(N) << std::endl;
	}
}

int CountPrime(int N)
{
	int Counter = 0;

	for (int i = 1; i <= N; i++)
	{
		Counter = Counter + CheckPrime(i);
	}

	return Counter;
}

int CheckPrime(int N)
{
	if (IsPrime(N))
		return 1;

	return 0;
}

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


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

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

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

bool isprime(int n);

int main()
{
	while(1)
	{
		int n,count=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=2;i<n;i++)
		{
			count+=isprime(i)?1:0;
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

bool isprime(int n)
{
	for(int i=2;i<=(int)sqrt(n);i++)
	{
		if(n%i==0)return false;
	}
	return true;
}

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

int main() {
  int cnt[1000000];
  for (int i = 0; i < 1000000; ++i) cnt[i] = 0;
  for (int i = 2; i < 1000000; ++i) {
    bool is_prime = true;
    for (int j = 2; j*j <= i; ++j) {
      if ((i % j) == 0) {
        is_prime = false;
        break;
      }
    }
    cnt[i] = cnt[i-1];
    if (is_prime)
      ++cnt[i];
  }
  int n;
  while(std::scanf("%d",&n) != EOF) {
    std::cout << cnt[n] << std::endl;
  }
  return 0;
}

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


int main()
{

	int i,n,count,num;
	deque<int> sosu;
	deque<int>::iterator it;
	bool flg;
	
	//テーブルを予め作成する
	bool prime[1000000] = {false};
	
	prime[2] = true;

	for( i = 3; i <= 1000000 ; i+=2 ) {
		flg = true;	
		for(it = sosu.begin(); it != sosu.end(); it++ ) {
			num = *it;
			if( i < num * num ){
				break;
			}
			if( (i % num ) == 0 ){
				flg = false;
				break;
			}				
		}
		if( flg == true ) {
			sosu.push_back( i );
			prime[i] = true;	
		}
	}
	
	while(cin >> n){
		count = 0;
		if( n == 2 )
			count = 1;
		else if( n < 2 )
			count = 0;
		else {
			for( i = 3; i <= n ; i+=2 ) {
				if( prime[i] == true )
					count++;
			}
			count ++;
		}
		cout << count << endl;
	}
			
	return 0;
}

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


int main(){
	int number,cnt=0;
	cin>>number;
	int* arr = new int[number+1];
	for (int i = 1; i <= number; i+=2)
	{
		arr[i-1]=0;
		arr[i]=1;
	}
	for (int i = 3; i < sqrt(number); i+=2)
		if (arr[i])
			for (int j = i+i; j <=number; j+=i)
				arr[j]=0;
	arr[2]=1;arr[1]=0;
	for (int i = 0; i <= number; i++)
		if (arr[i])
			++cnt;
	cout<<cnt<<endl;
}

C++: #include <stdio.h>

int ans ;
int N ;
bool prime[1000200] ;

void SE ( ) ;

int main ( ) 
{
	SE ( ) ;
	while ( scanf ( "%d" , &N ) == 1 ) {
		ans = 0 ;
		if ( N > 2 ) {
			ans++ ;
		}
		for ( int i = 3 ; i < N ; i += 2 ) {
			if ( prime[i] == false ) {
				ans++ ;
			}
		}
		printf ( "%d\n" , ans ) ;
	}
	return 0 ;
}

void SE ( )
{
	prime[0] = prime[1] = true ;
	for ( int i = 3 ; i < 1004 ; i += 2 ) {
		if ( prime[i] == false ) {
			for ( int j = i * i ; j < 1000020 ; j += i * 2 ) {
				prime[j] = true ;
			}
		}
	}
}