Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

int main(void) {

	//0005
	/*
	int a, b, G, R, L, r;
	while (cin >> a >> b) {
		R = a;
		L = b;
		int tmp;
		if (b > a) {
			tmp = a;
			a = b;
			b = tmp;
		}
		while (1) {
			r = a%b;
			if (r == 0)break;
			a = b;
			b = r;
		}
		G = b;
		R = R / G;
		L = L / G;
		cout << G << " " << R*L * G << endl;
	}
	*/
	//0006
	/*
	string name;
	cin >> name;
	int L = name.size();
	string Ans;
	for (int i = 0; i < L; i++) {
		Ans += name.substr(L-i-1, 1);
	}
	cout << Ans << endl;
	*/
	//0007
	/*
	int Dept = 100000;
	int week;
	cin >> week;
	for (int i = 0; i < week; i++) {
		Dept = Dept * 1.05;
		if (Dept % 1000 == 0) {
			Dept = (Dept / 1000);
		}
		else {
			Dept = (Dept / 1000 + 1);
		}
		Dept = Dept * 1000;
	}
	cout << Dept << endl;
	*/
	//0008
	/*
	int a, b, c, d;
	int n;
	int count[51];
	for (int i = 0; i < 51; i++) {
		count[i] = 0;
	}
	for (a = 0; a < 10; a++) {
		for (b = 0; b < 10; b++) {
			for (c = 0; c < 10; c++) {
				for (d = 0; d < 10; d++) {
					count[a + b + c + d]++;
				}
			}
		}
	}
	while (cin >> n) {
		cout << count[n] << endl;
	}
	*/
	int n;
	int i, j;
	int flag;
	int count;
	while (cin >> n) {
		count = 4;
		if (n < 10) {
			if (n == 0 || n == 1) {
				cout << "0" << endl;
			}
			else if (n == 2) {
				cout << "1" << endl;
			}
			else if (n == 3 || n == 4) {
				cout << "2" << endl;
			}
			else if (n == 5 || n == 6) {
				cout << "3" << endl;
			}
			else if (n == 7 || n == 8 || n == 9) {
				cout << "4" << endl;
			}
		}else {
			for (i = 10; i <=n; i++) {
				flag = 0;

				for (j = 3; j < sqrt(i) + 1; j += 2) {
					if (i % 2 == 0 || i%j == 0) {
						flag = 1;
						break;
					}
				}
				if (flag == 0) {
					count++;
				}
			}
			cout << count << endl;
		}
	}
	return 0;
}

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

int prime[1000000];


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


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

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

int main(){
	int n,k,p[100000],s,i,j;
	k=1;
	p[0]=2;
	for(i=3;i<99999;i+=2){
		s=0;
		for(j=0;j<k;j++){
			if((i%p[j])==0){
				s++;
			}
		}
		if(s==0){
			p[k]=i;
			k++;
		}
	}
	
	while(cin >> n){
		for(i=0;n>=p[i];i++){
		}
		cout << i <<"\n";
	}
return 0;
}

C++: #include <iostream>

using namespace std;

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

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

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

int mkprime( void );

int main( void )
{
	int n, i, result;

	prime[0] = 2;

	mkprime();

	while( std::cin >> n ){
		for( i = 0; prime[i] <= n; i++ ){}
		
		std::cout << i << std::endl;
	}
	
	return 0;
}

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

	for( i = 3; i < N_MAX + 1; i += 2 ){
		for( j = 0; j < endindex; j++ ){
			if( i % prime[j] == 0 ){
				break;
			}
		}

		if( prime[j] == 0 ){
			prime[ endindex ] = i;
			endindex++;
		}
	}
}

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

int main(){
    bool is_prime[1000000];

    is_prime[0] = is_prime[1] = false;
    for(int i=2;i<1000000;i++)
        is_prime[i] = true;

    for(int i=2;i*i<1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<1000000;j+=i){
                is_prime[j] = false;
            }
        }
    }

    int n_prime[1000000];
    int cnt(0);
    for(int i=0;i<1000000;i++){
        if(is_prime[i]) cnt++;
        n_prime[i] = cnt;
    }

    while(1){
        int n;
        cin >> n;

        if(cin.eof())   break;

        cout << n_prime[n] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<string.h>
int main(){bool*v=new bool[500000];int m,n=999999,o,c,d,i,e;memset(v,1,c=n/2+1);for(i=m=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;for(o=m*2+1,d=o*3;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(;!(std::cin>>n).eof();){if(n<3)e=n>1;else{c=(n&1?n:--n)/2+1;e=1;for(i=1;i<c;)e+=v[i++];}printf("%d\n",e);}delete[]v;}

C++: #include <iostream>

#define N 100000

using namespace std;

int main() {
	int n;
	bool p[N];
	for(int i = 0; i <= N; i++) p[i] = 0;
	for(int i = 3; i <= N; i += 2) p[i] = 1;
	p[2] = 1;
	for(int i = 0; i < N; i++){
		if(!p[i]) continue;
		for(int j = 2 * i; j < N; j += i) p[j] = 0;
	}

	while(cin >> n){
		int j = 0;
		for(int i = 0; i <= n; i++){
			if(p[i]) j++;
		}
		cout << j << endl;
	}	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){

	int a,n,j;
	cin>>a;
	n=0;
	for(int i=2;i<=a;i++){
		for(j=2;j<i;j++){
			if(i%j==0)break;
		}
		if(i == j) n += 1;
	}

	cout<<n<<endl;
}

C++: #include<stdio.h>
#include<math.h>
int gurobal[1000001]={0};
int main(void)
{
	int n=0;
	int i=0,j=0;
	int heihoukon=0;
	int count=0;
	while(scanf("%d",&n)!=EOF)
	{
		count=0;
		gurobal[1]=0;
		for (i=2;i<=n;i++)
		{
			gurobal[i]=1;
		}
		(int)heihoukon=sqrt((double)n);
		for (i=2;i<=heihoukon;i++)
		{
			if (gurobal[i]!=0)
			{
				for (j=i*2;j<=n;j+=i)
				{
					gurobal[j]=0;
				}
			}
		}
		for (i=2;i<=n;i++)
		{
			if (gurobal[i]!=0)
			{
				count++;
			}
		}
		printf("%d\n",count);
	}

	return 0;
}

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

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

int count_prime(int n)
{
	int count = 0;
	for (int i=2;i<=n;i++) 
		if (check_prime(i)) 
			count++;

	return count;
}

int main()
{
	int n = 0;
	vector<int> result;

	while(cin >> n) 
		result.push_back(count_prime(n));

	for(int i=0;i<result.size();i++)
		cout << result[i] << endl;

	return 0;
}

C++: #include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;

int prime[300000],nprime;
int mark[1000002];
int i,j;

int sieve(int n)
{
    int limit=sqrt(n*1.)+2;
    mark[1]=1;
    for(i=4;i<=n;i+=2) mark[i]=1;
    prime[nprime++]=2;
    for(i=3;i<=n;i+=2){
        if(!mark[i]){
            prime[nprime++]=i;
            if(i<=limit){
                for(j=i*i;j<=n;j+=i*2){
                    mark[j]=1;
                }
            }
        }
    }
    printf("%d\n",nprime);
    nprime=0;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){
        sieve(n);
    }
    return 0;
}