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<bits/stdc++.h>
using namespace std;
int prime[1000005],e;
bool is_prime[1000005];
int presum[1000005];
void solve()
{
    prime[0]=prime[1]=1;
    for(int i=2;i<=1000000;i++)
    {
        if(!is_prime[i])
        {
            prime[++e]=i;
            if((long long)i*i>1000000) continue;
            for(int j=i*i;j<=1000000;j+=i) is_prime[j]=1;
        }
    }
}
void pre()
{
    presum[0] =presum[1]= 0;
    for(int i = 2; i <=1000000; i++)
        presum[i] = is_prime[i] ? presum[i - 1]: presum[i - 1]+1;
}
int main()
{
    int n;
    solve();
    pre();
    //cout<<e;
    while(cin>>n)
    {
       cout<<presum[n]<<endl;
    }

   return 0;
}

C++: #include<iostream>
using namespace std;
bool prime(int n){
	for(int i=2;i<n;i++){
		if(n%i==0)return false;
	}
	return true;
}
int main(){
	int a;
	while(cin>>a){
	int sum=0;
	for(int j=2;j<a;j++){
		if(prime(j))sum++;
	}
	cout<<sum<<endl;
	}
}

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

using namespace std;

const int maxn=1e6+5;

int isprime[maxn];

int solve(int n)
{
    int p=0;
    for(int i=2;i<=n;i++){
        if(!isprime[i]){
            p++;
        }
        for(int j=2*i;j<=n;j+=i){
            isprime[j]=1;
        }
    }
    return p;
}

int main()
{
    int n;
    while(~scanf("%d",&n)){
        cout<<solve(n)<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
    int t;
    while(cin >> t){
        cerr << t << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

map<int, int> prime_factor(int n) {
	map<int, int> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int eratosthenes(int n) {
	bool is_prime[n + 1];
	memset(is_prime, true, sizeof(is_prime));
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ans;
}

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

	bool is_prime[1000001];
	memset(is_prime, true, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	rep(i, 2, 1000000 + 1) {
		if(is_prime[i]) {
			for(int j = 2 * i; j <= 1000000; j += i) is_prime[j] = false;
		}
	}

	int n;
	while(cin >> n) {
		int rsl = 0;
		rep(i, 0, n + 1) {
			if(is_prime[i]) rsl++;
		}
		cout << rsl << endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

int main(){
	int n;
	vector<int> prime;
	int count=0;
	int tmp[3][100];
	int k=0,max=0;
	while(cin>>n){
		tmp[0][k++]=n;
		if(max<n) max = n;
		if(n==1){
			tmp[1][k-1]=0;
		}
		else if(n==2){
			tmp[1][k-1]=1;
		}
		else if(n==3){
			tmp[1][k-1]=2;
		}
	}
	//cout<<"hoge\n";
	prime.push_back(2);
	prime.push_back(3);
	//count[1]=0;
	//count[2]=1;
	//count[3]=2;
	//cout<<"hoge\n";
	count = 2;
	for(int i=4;i<max+1;i++){
		/*if(i%2==0){
			count[i]=prime.size();
		}
		else if(i%3==0){
			count[i]=prime.size();
		}
		else{
			*/
			count++;
			prime.push_back(i);
			for(int j=0;j<prime.size()-1;j++){
				if(i%prime[j]==0){
					count--;
					prime.pop_back();
					break;
				}
			}
			for(int j=0;j<k;j++){
				if(tmp[0][j]==i){
					tmp[1][j]=count;
				}
			}
		//}
	}
	//cout<<"hoge";
	/*for(int i=0;i<15;i++){
		cout<< count[i] << endl;
	}*/
	for(int j=0;j<k;j++){
		cout<<tmp[1][j]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define N_MAX 999999


int prime[( N_MAX + 1 ) / 2 ];
int memo[ N_MAX + 1 ];

int mkprime( void );

int main( void )
{
	int n;

	prime[0] = 2;
	memo[1] = 0;
	memo[2] = 1;

	mkprime();

	while( std::cin >> n ){
		std::cout << memo[n] << std::endl;
	}
	
	return 0;
}

int mkprime( void ){
	int i, j, endindex = 1;

	for( i = 3; i < N_MAX + 1; i++ ){
		for( j = 0; prime[j] * prime[j] <= i; j++ ){
		if( i % prime[j] == 0 ){
				goto tag;
			}
		}

		prime[ endindex ] = i;
		endindex++;

tag:
		memo[i] = endindex;
	}
}