Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


void initialize(vector<int> &search_list, int num);

void era(vector<int> &search_list, vector<int> &prime_list, int num);
  

int main(int argc, char* argv[]){
  
  int num;

  while (cin >> num){
    if (num == 1){
      cout << 0 << endl;
    }
    else{
      vector<int> search_list, prime_list;
      initialize(search_list, num);
      era(search_list, prime_list, num);
      cout << prime_list.size() << endl;
    }
  }
  return 0;
}

void initialize(vector<int> &search_list, int num){
  for (int i=2; i<=num; ++i){
    search_list.push_back(i);
  }
  return;
}

void era(vector<int> &search_list, vector<int> &prime_list, int num){
  do{
    vector<int>::iterator it = search_list.begin();
    int count = 1;
    int N = *it;
    prime_list.push_back(*it);
    while ((N*count) <= num){
      it = find(search_list.begin(), search_list.end(), (N*count));
      if (it != search_list.end()){
	it = search_list.erase(it);
      }
      ++count;
    }
  } while (!search_list.empty());
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1000000

static bool gosei[MAX];

void b() {
	for (int i = 2; i <= sqrt(MAX); i++)
		if (gosei[i] == false) {
			for (int j = 2, k = 0; (k = i*j) <= MAX; j++)
				gosei[k] = true;
		}
}

int c(int n) {
	int cnt = 0;
	for (int i = 2; i <= n; i++)
		if (!(gosei[i]))cnt++;
	return cnt;
}

int main() {
	b();
	int n;
	while (cin >> n)
		cout << c(n) << endl;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;

  vector<int> nums;
  nums.reserve(n+1);
  for (int i = 0; i <= n; i++)
    nums.push_back(i);

  for (int i = 2; i <= n; i++) {
    if (nums[i] == 0)
      continue;
    int hoge = nums[i];
    for (int j = i+1; j <= n; j++) {
      if (nums[j] == 0)
        continue;
      else if (nums[j] % hoge == 0)
        nums[j] = 0;
    }
  }

  int result = 0;
  for (int i = 2; i <= n; i++)
    if (nums[i])
      result++;
  cout << result << endl;
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#define N 1000000
int n;
bool prime[N];
int num[N];
int main() {
    memset(prime, 1, sizeof prime);
    //for (int i=0;i<N;++i)prime[i]=true;
    prime[1] = prime[0] = num[0] = false;
    for (int i = 2; i < N; ++i)
        if (prime[i]){
            for (int j = 2 * i; j < N; j += i) prime[j] = false;
        //if (i%1000==0)
        //printf("%d %d\n",i,prime[i]);
    }
    for (int i = 1; i < N; ++i) num[i] = prime[i] + num[i-1];
    while (~scanf("%d", &n)) printf("%d\n", num[n]);
    return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main()
{
    int n;
    set<int> prime;
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            bool is_prime = true;
            int tmp = 2;
            for(auto num : prime)
            {
                if(num >= i) break;
                if(i % num == 0)
                {
                    is_prime = false;
                    break;
                }
                tmp = num;
            }
            for(int j = tmp; is_prime && j <= i / 2; j++)
            {
                if(i % j == 0)
                {
                    is_prime = false;
                    break;
                }
            }
            if(is_prime) 
            {
                prime.insert(i);
            }
        }
        int cnt = prime.size();
        for(auto it = prime.rbegin(); it != prime.rend(); it++)
        {
            cerr << *it << ' ';
            if(n < *it) cnt--;
            else break;
        }
        cout << cnt << endl;
    }
}

C++: // AOJ 009

#include <iostream>
#define MAX_NUMBER 50 //1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples (int prime) {
	for (int i = prime*2; i < MAX_NUMBER;i+=prime) {
		isPrime[i] = false;
	}
	return;
}	

int CountPrimes(int n) {
	int count = 0;
	for (int i = 1;i <= n;i++) {
		if (isPrime[i]) count++;
	}
	return count;
}

int main() {
	for (int i = 0;i < MAX_NUMBER;i++) {
		isPrime[i] = true;	
	}
	isPrime[1] = false;
	
	for (int i = 1;i < MAX_NUMBER;i++) {
		if (isPrime[i]) {
			SetFalseToMultiples(i);
		}
	}
	int n;
	while (cin >> n) {
		cout << CountPrimes(n) << 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 true;
}

int main(){
	int n;
	while(cin>>n){
		int sum=1;
		for(int i=3;i<=n;i+=2){
			if( isPrime(i) )sum++;
		}
		if(n==1)sum=0;
		cout<<sum<<endl;
	}
}

C++: // 2015/05/19 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>
#include <cmath>
using namespace std;
int main(){
    int n;
    char prime[1000000] = {1, 1};
    for(int k = 2; k < 1000; k++){
        if(prime[k] == 0){
            for(int j = k * k; j < 1000000; j += k)
                prime[j] = 1;
        }
    }
    while(cin >> n){
        int res = 0;
        for(int j = 2; j <= n;j++) 
			if(prime[j] == 0) 
				res++;
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int k, n, s, t, i = 0, j, maxV = INT_MIN, A[30] = {};
	while (cin >> k) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0;
	bool isP = false;
	for (k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			t = (s - 1) / k;
			for (j = 2; j <= t; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}

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

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long int ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	vi v(1000010, 1);
	vi copy(1000011, 1);
	ll n, c = 0;
	double rt;

	v[0] = 0;

	while (cin >> n){
		rt = sqrt(n);
		FOR(i, 1, rt){
			if (v[i] == 1){
				for (int j = i + 1; (i + 1)*j <= n; j++){
					v[(i + 1)*j - 1] = 0;
				}
			}
		}
		/*REP(i,n){
			cout << v[i] << "\n";
		}*/
		REP(i, n){
			if (v[i] == 1)c++;
		}
		cout << c << "\n";
	}
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n,c;
	while(scanf("%d",&n)!=EOF){
		c=1;
		for(int i=3;i<=n;i+=2)if(isprime(i))c++;
		printf("%d\n",c);
	}
	return 0;
}