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>
#include <vector>
using namespace std;
#define MAX 1000000
int main( void )
{
	vector <bool> prime( MAX+1, false );
	prime[2] = true;
	for ( int i = 3; i <= MAX; i += 2 )
	{
		prime[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( prime[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				prime[j] = false;
			}
		}
	}

	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		int cnt = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( prime[i] )
			{
				cnt++;
			}
		}

		if ( n == 2 )
			cnt = 1;
		else if( n <= 1 )
			cnt = 0;

		cout << cnt << endl;

	}

	return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	int premaxin=1;


	for(i=0;i<100000;i++){
		c[i]=1;
		data[i]=0;
	}
	c[0]=c[1]=0;

	while(scanf("%d",&n)!=EOF){

		if(premaxin<n){
			for(i=0;i<=n;i++){
				if(c[i]==1){
					if(premaxin>i){
						j=premaxin;
					}else{
						j=i+1;
					}
					for(;j<=n;j++){
						if(j%i==0){
							c[j]=0;
						}
					}
				}
			}

			count=data[premaxin];
			for(i=premaxin+1;i<=n;i++){

				if(c[i]==1){
					count++;
				}
				data[i]=count;
			}
		}

		printf("%d\n",data[n]);
	}
	return 0;
}

C++: #include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

vector<int> vec;

void makesosuu(void){
	FOR(i, 2, 999999){
		if(i == 2){
			vec.pb(i);
		}else if(i % 2 != 0){
			bool flag = true;
			int j = 3;
			while(j * j <= i){
				if(i % j == 0){
					flag = false;
					break;
				}
				j += 2;
			}
			if(flag) vec.pb(i);
		}
	}
	return;
}

int sosuu(int n){
	int i = 0;
	while(vec[i] <= n && i < vec.size()) ++i;

	return i;
}

int main(){
    int n;
    makesosuu();
    while(cin >> n){
        cout << sosuu(n) << endl;   
    }	
}

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

int is_it_primeNum(int n)
{
	int a = 1;
	if (n == 0 || n == 1)
		return 0;
	else if (n == 2)
		return 1;
	else if(n % 2 == 0)
		return 0;
	else{ 
		for(int i=3;i<n/2;i+=2){
			if (n%i==0){
				a = 0;
				break;}
		}
	}
	return a;
}
int how_much_primeNum(int n)
{
	int ans = 0;
	for(int i=2;i<=n;i++){
		ans += is_it_primeNum(i);
	}
	return ans;
}

int main()
{
	int n;
	while(cin>>n)
		cout << how_much_primeNum(n) << endl;
	return 0;
}

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

void sieve(int n, list<int> &primes)
{
    vector<bool> v(n + 1, true);

    // check
    for (int i = 3, end = sqrt(n); i <= end; i += 2) {
        if (!v[i])
            continue;
        for (int j = i * i, skip = i * 2; j <= n; j += skip)
            v[j] = false;
    }

    primes.push_back(2);
    for (int i = 3; i <= n; i += 2)
         if (v[i])
            primes.push_back(i);
}

int main()
{
    list<int> primes;
    vector<int> inputs;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        int count = 0;
        for (auto p : primes) // find
            if (p == x) {
                count++;
                break;
            } else if (p > x)
                break;
            else
                count++;
        cout << count << endl;
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int d[1000000]={},p[1000000]={};
void calc(){
	for(int i=2;i<1000000;i++){
		if(d[i]==0){
			for(int j=2;j<1000000;j++){
				if(i*j>1000000) break;
					d[i*j]=1;
			}
		}
	}
	for(int i=2;i<1000000;i++){
		if(d[i]==0)
		p[i]=p[i-1]+1;
		else
		p[i]=p[i-1];
	}
}
int main(){
	calc();
	int n;
	while(cin>>n,n){
		cout<<p[n]<<endl;;
	}
	return 0;
}

C++: #include <stdio.h>
#include <cmath>

using namespace std;

#define REP(a, i, n) for (int i = a; i <= n; ++i)

const int MAX_N = 1e6 - 1;
bool memo[MAX_N + 1];

bool isPrime(int n) {
    if (memo[n]) return true;

    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

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

    memo[n] = true;
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {

    REP(0, i, MAX_N) {
        memo[i] = false;
    }

    int n = 0; // 999,999
    while(scanf("%d", &n) != EOF) {
        int cnt = 0;
        REP(1, i, n) {
            if (isPrime(i)) cnt++;
        }

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

    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];
	std::vector<int> result;

	//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:素数の個数
inline 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;
int a[1000000],b[1000000];
int main()
{
	int i,j,k,m=0,n=0;
	for(i=2;i<=1000000;i++)
	{
		if(a[i]!=1)
		{
			j=i*2;
			while(j<1000000){a[j]=1;j=j+i;}
			n++;
		}
		b[i]=n;
	}
	while(cin>>n)
	{
		cout<<b[n]<<endl;
	}
	return 0;
}

C++: #include <iostream>

int func(int n){
	int i, count = 0;

	while (1 < n){
		for (i = 2; i < n; i++){
			if (n%i == 0){
				break;
			}
		}
		if (i == n){
			count++;
		}
		n--;
	}
	return count;
}


int main(){
	int input;

	while (std::cin >> input){
		std::cout << func(input) << "\n";
	}

	return 0;
}