Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin>>n){
        int count=0;
        for (int i = n; 1 < i ; i--) {
            int prime_flag= 1;
            for (int j = i - 1 ; 1 < j ; j--) {
                if(i%j==0){
                    prime_flag= 0;
                }
            }
            count+=prime_flag;
        }
        cout<<count<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool flag[10000001];

int main(){
    int n=0,ans=0;
	for(int i=0;i <= 1000000;i++){
		if(i<=1)flag[i]=false;
		else flag[i]=true;
	}
	for(int i=2;i <= 1001 ;i++){
		if(flag[i]==true){
			for(int j=i*2 ; j<=1000000 ; j=j+i){
				flag[j] = false;
			}
		}
	}
    while(cin>>n){
		ans=0;
		for(int i=0;i <= n;i++){
			if(flag[i]==true){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

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

const int M = 1000010;
int prime[M];
bool isprime[M];

bool is_prime(int n);  
int sieve(int n);  

int main ( )
{
    int n;
    while(~scanf("%d",&n))
        printf("%d\n",sieve(n));

    return 0;
}

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

    return n!=1;
}

int sieve(int n)
{
    int p=0,i;
    for( i=0;i<=n;i++)
        isprime[i] = true;
    isprime[0] = isprime[1] = false;
    i++;
    for( i=2;i<=n;i++)
        {
        if(isprime[i])
        {
            prime[p++] = i;
            for(int j=2*i;j<=n;j+=i)
                isprime[j] = false;
        }
    }
    i++;
    return p;
}

C++: #include <iostream>
#include <string>
#include <array>
#include <cstdlib>
#include <cmath>

int main() {
	std::array<char, 1000000> is_prime_table = { 0, 0, 1 };
	for( int i=3; i<=is_prime_table.size(); i+=2 ) {
		if ( [&i]() -> bool
		{
			for( int j=3; j<=std::sqrt(i); j+=2 )
				if ( i % j == 0 )
					return false;
			return true;
		}() )
			is_prime_table[i] = 1;
	}
	
	std::string line;
	while( std::getline( std::cin, line ) ) {
		int const num = std::atoi( line.c_str() );
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 )
			if ( is_prime_table[i] == 1 )
				++result;

		std::cout << result << std::endl;
	}
}

C++: #include <iostream>
#include <algorithm>
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を数えていない分
	return ct;
	delete[] prime;
}

C++: #include <bits/stdc++.h>
#define MAX_N 1000000
using namespace std;
bool prime[MAX_N];
int table[MAX_N];

void initialize() {
    int p = 0;
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false;
    for(int r = 2; r * r <= MAX_N; r++) {
        if(prime[r]) {
            table[p++] = r;
            for(int c = r * 2; c <= MAX_N; c+= r) {
                prime[c] = false;
            }
        }
    }
}


int main(void) {
    initialize();
    int num;
    while(cin >> num) {
        int cnt = 0;
        for(int r = 0; table[r] <= num; r++) cnt++;
        cout << cnt << endl;
    }
    return(0);
}

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

int main(){
	const int max_num=1000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

C++: #include <cstdio>
#include<cmath>
using namespace std;
int n,sum,c,flag;
int a[1000000] = {0};
int main()
{
	c = 1000000;
	for(;c > 0;c--){
		flag = 0;
		for(int i = 2;i <= sqrt(c);i++){
			if(c % i == 0)
				flag = 1;
		}
		if(flag == 0)
			a[c] = c;
	}
	while(scanf("%d",&n) != EOF){
		sum = 0;
		for(int j = n;j > 1;j--){
			if(a[j] != 0)
				sum++;
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

#define MAXINT 1000000
bool isprime[MAXINT];
ll int sum[MAXINT];
void makeprime(){
	REP(i,MAXINT) isprime[i] = true;
	FOR(i,2,sqrt(MAXINT)+1){
		FOR(j,i+1,MAXINT-1){
			if(j%i==0) isprime[j] = false;
		}
	}
}

int main(){
	makeprime();
	sum[0] = 0;
	sum[1] = 0;
	sum[2] = 1;
	/*FOR(i,3,MAXINT){
		if(isprime[i]) sum[i] = sum[i-1]+1;
		else sum[i] = sum[i-1];
	}*/
	ll int n;
	while(cin >> n){
		ll int ans = 0;
		REP(i,n) if(isprime[i]) ans++;
		cout << ans << endl;
	}
}