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++: #include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9


bool primes[1000000];

void make_prime(){
	primes[0] = primes[1] = true;
	for(int i=2; i*i<=1000000; i++)if( !primes[i] )
		for(int j=i*2; j<1000000; j+=i)primes[j]=true;
}

int main(){
	int n,ret;
	make_prime();
	while(~scanf("%d",&n)){
		ret = 0;
		for(int i=2; i<=n; i++)if( !primes[i] )ret++;
		printf("%d\n",ret);
	}
	return 0;
}

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


int main()
{
	int n;
	
	while(cin >> n)
	{
		if (n>999999) continue;
		int i, j;
		int k = 0;
		for (i = 2; i <= n; i++)
		{
			int c = 0;
			for(j = 1; j<=i /2; j++)
			{
				if(i % j == 0)
				{
					c++;
					if (c > 1) break;
				}
			}
			if (c == 1)
			{
				k++;
			}
		}
		cout << k << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

bool prime(int n) {
	if (n < 2) return false;
	for (int i = 2; i < sqrt(n) + 1; i++) {
		if (n % i == 0) return false;
	}
	return true;
}

int main() {
	vector<int> v = vector<int>(1, 0);
	for (int i = 1; i < 1000000; i++) {
		if (prime(i)) {
			v.push_back(v.back() + 1);
		} else {
			v.push_back(v.back());
		}
	}
	int n;
	while (cin >> n) {
		cout << v[n] + 1 << endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

int t;

int main(){
	int *prime;
	prime = (int *)malloc(1000010*sizeof(t));
	if(prime==NULL) cout<<"no mem\n";
	rep(i,1000010){
		prime[i]=true;
	}
	prime[0]=prime[1]=false;
	for(int i=2;i<1000010;i++){
		if(prime[i]){
			for(int j=i*2;j<1000010;j+=i){
				prime[j]=false;
			}
		}
	}
	//rep(i,30) cout<<i<<" "<<prime[i]<<endl;
	int *sum;
	int num=0;
	sum=(int *)malloc(1000010*sizeof(t));
	if(sum==NULL) cout<<"no mem\n";
	rep(i,1000010){
		if(prime[i]){
			num++;
		}
		sum[i]=num;
	}
	int n;
	while(cin>>n){
		cout<<sum[n]<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=1e7+5;
int pri[MAX];
bool py[MAX];
int c0=0;
void isprime()
{
	memset(py,true,sizeof(py));
	int t=sqrt(MAX);
	pri[0]=pri[1]=false;
	for(int i=2;i<=t;i++)
	{
		if(py[i])
		{
			for(int j=2*i;j<=MAX;j+=i)
			py[j]=false;
			pri[c0++]=i;
		}
	}
}
int main()
{
	c0=0;
	isprime();
	while(cin>>n)
	{
		int c=0;
		for(int i=0;i<c0;i++)
		{
			if(pri[i]<=n) c++;
		}
		cout<<c<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
while(~scanf("%d",&n)){
int* table =  new int[n+1];
fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i<=n;i++){
if(table[i] && !is_prime(i)) {
for(int j=i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
// for ref

#include <iostream>
#include <cstring>
#define Rep(i, b, e)\
    for (int i = (int)b; i < (int)e; i++)

using namespace std;

const int MAXN = 999999;
bool isPrime[MAXN];

int countPrime(int n) {
    memset(isPrime, true, sizeof isPrime);
    Rep(i, 0, 1000)
        isPrime[i] = true;

    isPrime[0] = false;
    isPrime[1] = false;
    // isPrime[2] = true;
    // isPrime[3] = true;

    Rep(i, 2, n) {
        Rep (k, 2, 100) {
            isPrime[i*k] = false;
        }
    }

    int primeCount = 0;
    int j = 0;
    // while (primeCount < n) {     // GS q
    while (j <= n) {
        if (isPrime[j]) {
            // cout << primeCount << " th prime\t";
            // cout << j << endl;
            primeCount++;
        }
        j++;
    }

    return primeCount;
}

int num;

int main()
{
    while (cin >> num) {
        cout << countPrime(num) << endl;
    }
 //   cout << "Hello world!" << endl;
    return 0;
}

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

using namespace std;

int main()
{
int number;
bool TEST;
TEST = true;


cin>> number;
for(int i=2; i < number; i++)

{
if (number%i==0)
TEST = false;
break;

}

if (TEST == false)
cout << number << " is not prime";
else cout << number << " is prime";

}

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(void) {
	int n;
 while(cin >> n){	
    int count = 0;
    for(int i=2;i<=n;i++){
        if(IsPrime(i)) count++;
    }
    cout << count << endl;
    count = 0;
}

    return 0;
}

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

int main(){
    int n;
    while(cin >> n){
        int numOfPrime = 0;
        bool isPrime[n-1];
        for(int i=2;i<=n;++i){
            isPrime[i-2] = true;
        }
        for(int i=2;i<=sqrt(n);++i){
            if(!isPrime[i-2]){
                continue;
            }
            for(int j=i;j<=n;++j){
                if(j%i == 0 && i != j){
                    isPrime[j-2] = false;
                }
            }
        }
        for(int i=2;i<n;++i){
            if(isPrime[i-2]){
                ++numOfPrime;
            }
        }
        cout << numOfPrime << endl;
    }
}

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

using namespace std;

int main(){
  int i;
  vector<int> knownprime;
  vector<int> ans;
  bool flag;

  while(cin >> i){
    if(cin.eof()){
      break;
    }
    knownprime.clear();
    for(int d = 2; d <= i; d++){
      flag = true;
      for(int& p : knownprime){
	// ?????§??????????????£??????????´???°??§?????£??????????????¨?????§?????????????????°??°???????´???°??¨??????
	if(d%p == 0){
	  flag = false;
	  break;
	}
      }
      if(flag){
	knownprime.push_back(d);
      }
    }
    ans.push_back(knownprime.size());
  }
  for(int& d : ans){
    cout << d << endl;
  }

}

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

int prime[1000000];
void initTbl(){
	//sieve of Eratosthenes
	// 0 : prime
	// 1 : not prime
	memset(prime, 0, sizeof(prime));
	prime[0] = 1;
	prime[1] = 1;

	int limit = 1000000;
	for(int i=4; i<limit; i+=2){
		prime[i] = 1;
	}

	for(int j=3; j*j<=limit; j+=2){
		for(int k=j; j*k<=limit ;k+=2){
			prime[j*k] = 1;
		}
	}
}

//0009
int main()
{
	int n=10;
	initTbl();

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

		for(; n>0; n--){
			if(!prime[n])
				++cnt;
		}
		cout << cnt << endl;

	}
  return 0;
}