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 <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int n;

	while (cin >> n) {
		int counter = 1;
		
		if(n < 1000){
			for (int i = 3; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		}else if(n < 10000){
			counter = 168;
			for (int i = 1001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 100000){
			counter = 1229;
			for (int i = 10001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 200000){
			counter = 9592;
			for (int i = 100001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 300000){
			counter = 17984;
			for (int i = 200001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 400000){
			counter = 25997;
			for (int i = 300001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 500000){
			counter = 33860;
			for (int i = 400001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 600000){
			counter = 41538;
			for (int i = 500001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 700000){
			counter = 49098;
			for (int i = 600001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 800000){
			counter = 56543;
			for (int i = 700001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if(n < 900000){
			counter = 63951;
			for (int i = 800001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else if (n < 999999){
			counter = 71274;
			for (int i = 900001; i <= n; i=i+2) {
				int kari = 1;
				for (int j = 3; j < i; j=j+2) {
					kari = i % j;
					if(kari == 0) {
						break;
					}
				} if (kari != 0) {
					counter++;
				}
			}
		} else {
			counter = 78498;
		}
		cout << counter << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int shusu[35];
	int d=0;
	for(int i=2;;i++)
	{
		int bj=1;
		for(int j=2;j<=sqrt(i);j++)
		{
			if(i%j==0)
			{
				bj=0;
				break;
			}
		}
		if(bj==1)
		{
			shusu[d++]=i;
		}
		if(d==35)
		{
			break;
		}
	}
	int n;
	while(cin>>n)
	{
		for(int i=0;i<35;i++)
		{
			if(n<2)
			{
				cout<<0<<endl;
				break;
			}
			if(n>=shusu[i] && n<shusu[i+1])
			{
				cout<<i+1<<endl;
				break;
			}
		}
	} 
	return 0;
}

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

void AOJ0009()
{
	int n = 0;
	int prime[1000];
	int count = 0;
	for (int i = 2; i <= 1000; i++)
	{
		int j = 2;
		bool flag = false;
		for (j = 2; j <= i; j++)
		{
			if (i % j == 0)
				break;
		}
		if (i == j)
		{
			prime[count] = i;
			count++;
		}
	}

	while (cin >> n)
	{
		count = 0;
		while (prime[count] <= n)
		{
			count++;
		}
		cout << count << endl;
	}
}
int main()
{
	//AOJ0005();
	//AOJ0007();
	AOJ0009();
	return 0;
}

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

int main() {
	int n;

	while (cin >> n) {
		int count = 0;
		bool table[1000001] = { false };
		int upper = sqrt(n);

		table[1] = true;

		for (int i = 1; i <= upper; i++) {
			if (table[i] == false) {
				table[i] = true;
				count++;
				for (int j = i; j <= n; j += i) {
					table[j] = true;
				}
			}
		}

		for (int i = upper; i <= n; i++) {
			if (table[i] == false) {
				count++;
			}
		}

		cout << count << '\n';
	}

	return 0;
}