Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

bool IsPrime[1000000];
int PrimeNum[1000000];

int main()
{
    for (int i = 0; i < 1000000; i++)
    {
        IsPrime[i] = true;
    }
    int count = 0;
    PrimeNum[0] = PrimeNum[1] = 0;
    for (int i = 2; i < 1000000; i++) {
        if (IsPrime[i]) {
            count++;
            PrimeNum[i] = count;
            for (int j = 2 * i; j < 1000000; j += i) {
                IsPrime[j] = false;
            }
        }
        else
        {
            PrimeNum[i] = PrimeNum[i - 1];
        }
    }
    int n;
    while (cin >> n)
    {
        cout << PrimeNum[n] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int max = 1000100;
	bool prime[1000100];
	int dp[1000000];
	prime[0] = prime[1] = false;
	int ret=0;
	memset(prime,true,sizeof(prime));
	memset(dp,0,sizeof(dp));
	int hako[30];
	memset(hako,0,sizeof(hako));
	REP(i,30) cin >> hako[i];
	for(int i=2;i<sqrt(max);i++)for(int j=i*2;j<max;j=j+i){
		prime[j] = false;
	}
	REP(i,max){
		dp[i]=dp[i-1];
		if(prime[i])dp[i]++;
	}
	REP(i,30)	cout << dp[hako[i]] << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int prime[N], cnt;
bool st[N];
void init() {
    st[0] = st[1] = true;
    for(int i = 2; i < N; i++) {
        if(!st[i])  prime[cnt++] = i;
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = true;
            if(i % prime[j] == 0)   break;
        }
    }
}
int main() {
    init();
    // for(int i = 0; i < 10; i++)
    //     printf("%d ", st[i]);
    // puts("");
    int n, sum;
    while(cin >> n) {
        sum = 0;
        for(int i = 2; i <= n; i++)
            if(!st[i])
                sum++;
        printf("%d\n", sum);
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int prime(int);

int main() {

	int n;

	while(cin >> n) {
		if(n>999999)
			continue;
		cout << prime(n) << endl;
	}

	return 0;

}

int prime(int n) {

	int i, j, k=0, count=0;
	if(n==0||n==1)
		return 0;

	for(i=2; i<=n; i++) {
		for(j=2; j<i; j++) { 
			if(i%j==0)
				k=1;
		}
		if(k==0)
			count++;
		k=0;
	}

	return count;

}

C++: #include <iostream>
using namespace std;
int main(){
	int n , i , j;
	while(cin >> n ){
		int counter = 0;
		for( int i=1 ; i<=n ; i++ ){
			if( i%2 == 0 ){
				continue ;
			}
			int x = i;
			if( i>=6 )
				x = x /2;
			int temple=0;
			for( int j=1 ; j<=x ; j++ ){
				if( i%j == 0 )
					temple++;
			}
			if( temple == 2 )
				counter ++;
		}
		cout << counter << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main()
{
long n,i,j,*nn;
for(;;){
cin>>n;
if(cin.eof())break;
nn=new long [n+1];
nn[1]=0;nn[2]=1;
for(i=3;i<=n;i+=2)nn[i]=1;
for(i=4;i<=n;i+=2)nn[i]=0;
for(i=3;i<=n;i+=2){
for(j=i;j*j<=n;j+=2){
if(i%j==0){nn[i]=0;break;}
}
}
cout<<j<<endl;
delete [] nn;
}
return 0;
}

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

int main() {
	std::string line;
	while( std::getline( std::cin, line ) ) {
		int const num = std::atoi( line.c_str() );
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 ) {
			if ( [&i]() -> bool
			{
				for( int j=3; j<=std::sqrt(i); j+=2 )
					if ( i % j == 0 )
						return false;
				return true;
			}() )
				++result;
		}
		std::cout << result << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 10000000
bool prime[MAX-1];
int main(void){ 
  
  prime[0] = prime[1] = false;
  fill(prime,prime+MAX,true);

  int ans[1000000];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  for(int i = 2 ; MAX > i * i ; i ++){
    ans[i] = ans[i-1] + prime[i];
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  //cout<<endl;
  //for(int i = 0 ; i < 10 ; i ++)cout<<ans[i]<<endl;
  //*/
  int n;
  while(cin>>n){
    //cout<<n<<" ";
    cout<<ans[n]<<endl;
  }
  //*/
}

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

static const long MAX = 1000000L;
 
int main() {
    vector<long> prime;
    bool isPrime;
    long ans = 0;
    long n;
 
    long i, len = sqrt(MAX) + 1;
    long j, lenJ;
    long k;
     
    prime.push_back(2);

    for (i = 3; i <= len; i += 2) {
        isPrime = true;
        lenJ = prime.size();
        k = sqrt(i) + 1;
        for (j = 0; j < lenJ; j++) {
            if (k <= prime[j]) break;

            if (i % prime[j] == 0) {
                isPrime = false;

                break;
            }
		}

        if (isPrime) prime.push_back(i);
    }

    lenJ = prime.size();
     
    while (cin >> n) {
        ans = 1;

        if (n < 2) ans = 0;
         
        for (i = 3; i <= n; i += 2) {
            isPrime = true;

            k = sqrt(i) + 1;
            for (j = 0; j < lenJ; j++) {
                if (k <= prime[j]) break;

                if (i % prime[j] == 0) {
                    isPrime = false;

                    break;
                }
            }

            if (isPrime) ans++;
        }
         
        cout << ans << endl;
    }
 
    return 0;
}

C++: #include<stdio.h>
#include<math.h>
#define ullint unsigned long long int

// ?????°???(a^b %d ????¨????)
int modpow(ullint a, ullint b, long int d) {
  if (b == 0)     return 1;
  if (b % 2 == 0) return modpow(a*a % d, b/2, d);
  else            return a*modpow(a, b-1, d) % d;
}

// Miller???Rabin?´???°?????????
bool Miller_Rabin_Test(int n){
    int prime_list[4] = {2, 7, 61};

    if(n == 2 || n == 7 || n == 61){  // 2,7,61????´???°
        return true;
    }
    if(n == 1 || n%2 == 0){  // 2??\????????¶??°??¨1????´???°??§??????
        return false;
    }
    // n = 2^s*d + 1 (d????\???°)?????¢????????¢
    int d = n-1;
    int s = 0;
    while(d%2 == 0){  // d????\???°??????????????§?????¢
        d = d/2;
        s++;
    }
    for(int i=0; i<3; i++){  // ??????????????????3???
        bool isProbPrime = false;
        int a = prime_list[i];
        int r = modpow(a, d, n);
        if(r == 1 || r == n-1){
            isProbPrime = true;
            continue;
        }
        for(int j=0; j<s; j++){
            r = modpow(a, pow(2,j)*d, n);
            if(r == n-1){
                isProbPrime = true;
                break;
            }
        }
        if(!isProbPrime){
            return false;
        }
    }
    return true;
}

int Primenum[1000000];

int main(){
    Primenum[1] = 0;
    for(int i=1; i<=1000000; i++){
        if(Miller_Rabin_Test(i)){
            Primenum[i] = Primenum[i-1] + 1;
        }else{
            Primenum[i] = Primenum[i-1];
        }
    }
    for(int n; scanf("%d\n",&n) != EOF;){
        printf("%d\n",Primenum[n]);
    }
    return 0;
}