Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

#define MAX 999999

using namespace std;

int num_prime[MAX];
bool not_prime_flag[MAX];

int main()
{
    int n;

    for (int i = 1; i < MAX; ++i) {
        if(!not_prime_flag[i]){
            for (int j = 2; (i+1)*j-1 < MAX; ++j) {
                not_prime_flag[(i+1)*j-1] = true;
            }
        }
        num_prime[i]=num_prime[i-1]+!not_prime_flag[i];
    }
    while (cin>>n){
        cout<<num_prime[n-1]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,1000000){
	bool flg = true;
	REP(j,primes.size()) if(i % primes[j] == 0 ) {
	    flg = false;
	    break;
	}
	if(flg) primes.PB(i);
    }

    int n;
    while(true){
	cin >> n;
	if(cin.eof())break;
	int res = upper_bound(ALL(primes),n) - primes.begin();
	cout << res << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


const int Max=10000000;
bool prime[Max];
int main(void){
    int in;
    for(int i=0;i<Max;i++)prime[i]=true;
    prime[1]=false;
    for(int i=2;i<Max;i++){
        if(prime[i]){
            for(int s=i*2;s<=Max;s+=i)prime[s]=false;
        }
    }
    while(cin>>in){
        int cnt=0;
        for(int i=1;i<=in;i++){
            if(prime[i])cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 1000000
int prime[MAX];
bool is_prime[MAX+1];

int solve(int n){
  int p = 0; 
  //fill(prime,prime+MAX,true);
  for(int i = 0 ; i <= n ; i ++)is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(int i = 2 ; i <= n ; i ++){
    if(is_prime[i]){
      prime[p++] = i;
      for(int j = i + i ; j <= n ; j += i){
	is_prime[j] = false;
      }
    }
  }
  return p;
}
int main(void){ 
  
  long long int n;
  while(cin>>n){
    cout<<solve(n)<<endl;
  }
  
}

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

int main(){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b)
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}

}

C++: #include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair
typedef long long LL;


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(6);

  int INF = 1000000;

  int n;
  while(cin>>n){
    int res=0;
    bool notPrime[n+1];
    memset(notPrime,0,sizeof(notPrime));
    
    notPrime[0] = notPrime[1] = true;

    for(int i=2; i<=n; i++){
      if(!notPrime[i]){
	res++;
	for(int j=2*i; j<=n; j+=i){
	  notPrime[j] = true;
	}
      }
    }
    cout << res << endl;
  }


  return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 1000000

int main(){
  int n;
  bool p[MAX];
  p[0] = p[1] = false;
  for(int i=2;i<MAX;i++)p[i] = true;
  for(int i=2; i<MAX;i++){
	if(p[i]){
	  for(int j=i+i;j<MAX;j=j+i){
		p[j] = false;
	  }
	}
  }
  
  while(cin >> n){
	int cnt = 0;
	for(int i = 0;i<=n;i++){
	  if(p[i]) cnt++;
	}
	cout << cnt << endl;
  }
  
  return 0;
}

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

int main(){
	const int max_num=1000000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
        int n;

        while (cin >> n) {
                bool *isPrime = new bool[n + 1];
                isPrime[0] = false;
                isPrime[1] = false;
                for (int i = 2; i < n + 1; i++) {
                        isPrime[i] = true;
                }
                for (int i = 2; i <= (int)sqrt(n); i++) {
                        if (isPrime[i]) {
                                for (int j = i + 1; j <= n; j++) {
                                        if (isPrime[j]) {
                                                if (!(j % i)) {
                                                        isPrime[j] = false;
                                                }
                                        }
                                }
                        }
                }
                int ans = 0;
                for (int i = 2; i <= n; i++) {
                        if (isPrime[i]) {
                                ans++;
                        }
                }
                cout << ans << endl;
                delete [] isPrime;
        }

        return 0;
}