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 <algorithm>
using namespace std;

void AOJ0009()
{
	int n = 0;
	int prime[100000];
	int count = 0;
	for (int i = 2; i <= 100000; 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 isprime(int x){
	int i;
	if(x == 2 || x == 3) return 1;
	else if(x % 2 == 0) return 0;
	else{
		for(i = 3; i <= sqrt(x); i += 2){
			if(x % i == 0) return 0;
		}
		return 1;
	}
}

int main(){
	int n, i, count;
	while(cin >> n){
		count = 0;
		for(i = 2; i <= n; i++){
			if(i % 2 == 0 && isprime(i) == 1) count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
#define FOR(x,s,g) for(int x=(s);x<=(g);x++)
using namespace std;

int main(){
  int n;
  while(cin>>n){
    int count=0;
    FOR(i,2,n){
      int e=sqrt(i);
      FOR(j,2,e){
	if(i%j==0){
	  goto end;
	}
      }
      count++; 
    end:
      ;
    }
    cout<<count<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define INF 1<<25
#define LIM 1000000

using namespace std;

int n,sum,out;
bool prm[1000000];

void eucprime()
{
	FOR(i, 2, LIM)
	{
		if(prm[i] == 0)
		{
			for( int j = 2; j*i < LIM; j++)
			{
				prm[i*j] = 1;
			}
		}
	}
}
	

int main()
{
	while( cin >> n, !cin.eof())
	{
		CLR(prm);
		prm[0] = 1; prm[1] = 1;
		eucprime();
		
		int cnt=0;
		
		FOR(i, 0, n+1)
		{
			if(prm[i] == 0)
				cnt++;
		}
		
		cout << cnt << endl;
	}
	
	return 0;
}

C++: #include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V + 1];
int sum[MAX_V + 1] = {0};
int main() {
  int i, k, v, n, max = 0;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]){
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
    sum[i] = prime[i - 1] + sum[i - 1];
  }
  while(scanf("%d", &n) != EOF){
    printf("%d\n", sum[i + 1]);
  }
  return 0;
}

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


using namespace std;
#define MAX_NUM 999999


int do_count(bool *isPrime, int n);

int main(){
  int n;
  bool flag = false;
  int numPrime[MAX_NUM];
  int pivot = 1;
  
  for(int i=0;i<MAX_NUM;i++){
    numPrime[i] = 0;
  }
  
  while(cin >> n){
    int cnt=0;
    if(n < pivot){
      //      cout << "n < pivot" << endl;
      cnt = numPrime[n];
      cout << cnt << endl;
      continue;
      
    }
    
    if(n >= pivot){
      //      cout << "n >= pivot" << endl;
    // i???????????????
    }
    
    for(int i=pivot+1;i<=n;i++){
      flag = false;
      //?´???°?????????????????§??????
      for(int j=2;j<=sqrt(i);j++){
	if(i%j==0){
	  flag = true;
	  break;
	}
      }
      if(flag){
	numPrime[i] = numPrime[i-1];
	continue;
      }else{
	numPrime[i] = numPrime[i-1] + 1;
      }
    }
    cnt = numPrime[n];
    cout << cnt << endl;
  }
}

int do_count(bool *isPrime, int n){
  int cnt=0;
  for(int i=0;i<=n;i++){
    if(isPrime[i]==true){
      cnt++;
    }
  }
  return cnt;
}

C++: #include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];
int a[MAX_V] = {'0'};
int sum[MAX_V+1];
int main() {
  int i, k, v, j, m, n;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]) {
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  sum[0] = 0;
  for(m = 0; m < MAX_V; m++) {
    sum[m+1] = sum[m] + prime[m];
  }
  while( scanf( "%d", &n ) != EOF ) {
    printf( "%d\n", sum[n+1] );
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
	
	static int prime[999999 + 1];
	
	int i, j, k = 0, limit;
	
	for(i = 2; i < 1000000; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	
	for (i = 2; i < 1000000; i++){
		if(prime[i]){
			for (j = i + i; i < 1000000; j += i){
				prime[j] = 0;
			}
		}
	}
	while(scanf("%d", &limit) != EOF){
		for(i = 2; i <= limit; i++){
		
			if(prime[i]){
				k++;
			}
		}
	
		printf("%d\n", k);
	
	}
	return 0;
	
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n,sum,i,k,sqrtm;
	while(cin>>n)
	{
		sum=3;
		if(n<2){cout<<0<<endl;continue;}
		if(n==2){cout<<1<<endl;continue;}
		if(n==3){cout<<2<<endl;continue;}
		if(n==5 || n==4){cout<<3<<endl;continue;}
		 i=6;
	 while(i<n)
		{
			i++;
			if(i%2==0)continue;
			if(i%3==0)continue;
			if(i%5==0)continue;
			sqrtm=sqrt(i);
			for(k=2;k<=sqrtm+1;k++)
			{if(i%k==0)break;}
			if(k==sqrtm+2)sum++;
		}
		cout<<sum<<endl;
	}
}

C++: #include <cstdio>
int d[1000000],c[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i]){c[i]=r;continue;}
		c[i]=++r;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",d[n]);
	}
}

C++: #include <stdio.h>
int main(void){
	int k,j,a;
	char flag[1000000]={1,1};//0,1は除外する
	for(k=2;k<1000;k++){
		if(flag[k]==0){
			for(j=k*k;j<1000000;j+=k)
				flag[j]=1;
		}
	}
	while(~scanf("%d",&a)){
		k=0;
		for(j=2;j<=a;j++) if(flag[j]==0) k++;
		printf("%d\n",k);
	}
}