Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include<stdio.h>

int main(void){
  int n;
  while(scanf("%d",&n)!=EOF){
    if(n==1){
      printf("%d\n",0);
      break;
    }
    int p[50000];
    p[0]=2;
    int pi=1;
    int i=2;
    while(i<=n){
      int t=1;
      int j;
      for(j=0;j<pi;j++){
	if(i%p[j]==0){
	  t=0;
	  break;
	}
      }
      if(t==1){
	p[pi]=i;
	pi++;
      }
      i++;
    }
    printf("%d\n",pi);
  }
  return 0;
}

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

std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 1000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
}

C++: // 2012/11/07 Tazoe

#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(true){
		int n;
		cin >> n;

		if(cin.eof())
			break;

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

	return 0;
}

C++: #include <iostream>

using namespace std;
 
int main(void)
{
  int input;
  while(cin >> input)
  {
  bool isPrime[input];
  // if the index 0 do not count as the prime number
  isPrime[0] = false;
  /// if the index 1 do not count as the prime number
  isPrime[1] = false;
  // if the index 2 count as the prime number
  isPrime[2] = true;
  
	for(int i = 3; i <= input; i += 2)
    		isPrime[i] = true;
  	
	for(int i = 3; i * i <= input; i += 2)
   		 for(int j = i * i; j <= n; j += i)
     		 isPrime[j] = false;
  		 for(int i = 4; i <= n; i += 2)
    		 isPrime[i] = false;
  
	int count = 0;
 	

	for(int i = 0; i <= input; i++)
    	
	if(isPrime[i])
    	{
     	 count++;
      
    	}
  	cout << count << endl;
  }
}

C++: #include<stdio.h>
int n;
int num[1000000]={0};
int ans=0;

int del(int x){
    for(int i=x;i<999999;i++){
        if(i%x==0){
            num[i]=1;
        }
    }
    return 0;
}

int main(){
    while(scanf("%d",&n)!=-1){
        for(int i=0;i<999999;i++){
            num[i]=0;
        }
        ans=0;
        for(int i=1;i<n+1;i++){
            if(i==1){

            }
            else if(num[i]==0){
                ans++;
                del(i);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
#include <cctype>
#include<queue>
#include<stack>
#include<cstdio>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int ans=0;
		int d[999999+100]={};
		for(int i=2;i*i<=n;i++){
			if(d[i]==0){
				for(int j=2;j*i<=n;j++){
					d[j*i]++;
				}
			}
		}
		d[1]=1;
		for(int i=1;i<=n;i++){
					if(d[i]==0){
						ans++;
					}
							}
			cout<<ans<<endl;

		}
		
		return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n,visited,cnt=0;
  
  while(cnt<30){
    int count =0;
    cnt++;
    cin >> n;
    if(n==0)count =0;
    for(int j=2;j<=n;j++){
      visited=0;
      for(int i = 2;i<=n;i++){
	
	if(j%i==0&&j!=i)visited=1;
	else if(j%i==0&&j==i&&visited==0)count++;
	/*	cout<<"j/"<<j<<" i:"<<i <<" count:"<<count<<" visited"<<visited<<endl;    */ 
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

int main(){
	int n;
	int a[1000];
	int b;
	int i, j, p;
	int c[30];
	p = 0;
	while (scanf("%d", &n) != EOF){
		b = (int)pow((double)n, 0.5);
		c[p] = 0;
		a[0] = -1;
		for (i = 2; i <= b; i++){
			for (j = 2; j <= n / i; j++){
				a[i*j - 1] = -1;
			}
		}
		for (i = 1; i <= n; i++){
			if (a[i - 1] != -1){ c[p]++; }
			a[i - 1] = 0;
		}
		p++;
	}
	for (i = 0; i < p; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

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

int n, sum[1000001], isP[1000001];
vector<int> p;

int main() {
  for (int i = 2; i * i <= 1000000; i++) {
    bool ok = true;
    for (int j = 0; j < p.size(); j++) if (i % p[j] == 0) {
      ok = false;
      break;
    }
    if (ok) p.push_back(i);
  }
  for (int i = 2; i <= 1000000; i++) isP[i] = 1;
  for (int i = 0; i < p.size(); i++) {
    int k = 2;
    while (p[i] * k <= 1000000) isP[p[i] * k] = 0, k++;
  }
  for (int i = 1; i <= 1000000; i++) sum[i] = sum[i-1] + isP[i];
  while (scanf("%d", &n), n) {
    printf("%d\n", sum[n]);
    n = 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];

	//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:素数の個数
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 <vector>
using namespace std;

long long n;
vector<long long> p(1, 2);

int main()
{
	for (long long i = 3; i < 1000000; i += 2) {
		long long j = 0;
		bool f = 1;
		while(p[j] * p[j] <= i){
			if (i % p[j] == 0) {
				f = 0;
				break;
			}

			j++;
		}

		if (f)
			p.push_back(i);
	}

	while (cin >> n) {
		int m = 0;

		while (m < p.size() && p[m] <= n)
			m++;

		cout << m << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
  
bool isprime(int n) {
    for(int i=2; i*i <= n; i++) {
        if(n%i==0) return false;
    }
    return n != 1;
}
  
int main() {
int n;
while(cin >> n) {
int cnt = 0;
for(int i=2; i<=n; i++) if(isprime(i)) cnt++;
cout << cnt << endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#include <map>

int main() {
	int a;
	while (std::cin >> a) {
		int nSum = 0;
		for (int i = 2;i <= a;i++) {
			int flag = 0;
		for (int j = 2;j < i;j++) {
			if (i%j == 0) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			nSum += 1;
		}
	}
		std::cout << nSum << std::endl;
	}
	return 0;
}