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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

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

using namespace std;

int main() {
  int lim;
  int i,n;
  int count=1;
  bool isPrime=true;
  
  scanf("%d",&n);
  
  for(lim=2;lim<=n;lim++) {
  for(i=2;i<(int)(sqrt(lim)+1.0);i++) {
    if((lim%i)==0) {
      isPrime=false;
      count++;
      break;
    }
  }
  }
  printf("%d",n-count);
  return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string.h>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	bool fl[1000001];
	memset(fl, true, sizeof(fl));
	for (int i = 2; i <= sqrt(num); i++) {
		if (fl[i]) {
			for (int j = 2; j*i <= num; j++) {
				fl[i*j] = false;
			}
		}
	}
	for (int i = 2; i <= num; i++) {
		if (fl[i]) {
			count++;
		}
	}
	return count;
}

int main() {

	int num = 0;
	while (cin >> num) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

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

#define MAXN 1000000

int primeN[MAXN];

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

void calcPrimeN()
{
	primeN[0] = 0;
	for(int i=1; i<MAXN; i++)
	{
		if(isPrime(i)) primeN[i] = primeN[i-1] + 1;
		else primeN[i] = primeN[i-1];
	}
}

int main()
{
	calcPrimeN();
	
	int data;
	while(cin >> data)
	{
		cout << primeN[data] << endl;
	}

	return 0;
}

C++: #pragma GCC optimize "O3"
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define REP_FROM(i,m,n) for (int i = (m); (i) < int(n); ++(i))
#define REP_REV(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define REP_FROMREV(i,m,n) for (int i = (n)-1; (i) >= int(m); --(i))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#ifndef LOCAL
#define cerr if (false) cerr
#endif
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }
template <class T> T sq(T x) { return x * x; }
template <class T> T clamp(T a, T l, T r) { return min(max(a, l), r); } // [l, r]
const double EPS = 1e-10;
const double PI  = acos(-1.0);

vector<bool> ptable;

void sieve(LL max) {
	if(max+1 > ptable.size())
		ptable.resize(max+1, true);

	ptable[0] = ptable[1] = false;

	for(LL i = 2; i*i <= max; i++)
		if(ptable[i])
			for(LL j = 2; i*j <= max; j++)
				ptable[i*j] = false;
}

int main(int argc, char *argv[]) {
	// Something to do
	sieve(1000000);
	int n;
	while(cin >> n) {
		int cnt = count(ptable.begin(), ptable.begin()+n+1, true);
		cout << cnt << endl;
	}
	return 0;
}

C++: #include <iostream>

int main() {
	int input;
	// ??\???????????°????????????????????????????????????
	while (std::cin >> input) {
	int count = 0;
	for (; input > 1; input--) {
		bool fl = true;
		for (int i = 2; fl == true, i < input; i++)
			if (!(input % i))
				fl = false;

		if (fl)
			count++;
	}

			std::cout << count << std::endl;
	}
}

C++: /***********************************************************
エストラテネスの篩
O(n log n)よりははやい.
 ***********************************************************/

#include <vector>

std::vector<bool> prime_table(int N){
    std::vector<bool> is_prime(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i * i <= N; i++){
        if (is_prime[i]){
            for (int j = i * 2; j <= N; j += i) is_prime[j] = false;
        }
    }
    return is_prime;
}

std::vector<int> compute_primes(int N){
    std::vector<bool> is_prime = prime_table(N);
    std::vector<int> primes;
    for (int i = 0; i < N + 1; i++) if (is_prime[i]) primes.push_back(i);
    return primes;
}


// solution for http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp

#include <vector>
#include <iostream>

using namespace std;

int main(){
    int n;
    while(cin >> n){
        vector<int> primes = compute_primes(n);
        cout << primes.size() << endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
    int x;
    int i, j;
    int p[999999] = {};
    p[2] = 1;
    for (i = 3; i < 1000000; i++) {
        for (j = 2; ; j++) {
            if (!(i % j)) {
                break;
            } else if (j > sqrt(i)) {
                p[i] = 1;
                break;
            }
        }
    }
    while (scanf("%d", &x) != EOF) {
        j = 0;
        for (i = 0; i <= x; i++) {
            j += p[i];   
        }
        printf("%d\n", j);
    }
    return 0;
}

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

  prime_list.push_back(2);
  for (int i = 3; i < 50; i++) {
    for (int j = 0; j < prime_list.size(); j++) {
      if(i%prime_list[j] == 0) {
        flag = false;
        break;
      } else {
        flag = true;
      }
    }
    if (flag) {
      prime_list.push_back(i);
    }
  }

  int data, count;
  while(cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] < data; i++, count = i);
    cout << count << endl;
  }
}