Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

C++: #include <stdio.h>
#include <stdlib.h>

int main()
{
	int testcase, i;

	scanf("%d", &testcase);	
	for (i=0; i<testcase; i++)
	{
		int num, j=2, count = 0;				
		scanf("%d", &num);

		int* check = (int*) malloc(sizeof(int)*num);			

		int k;
		for (k=0; k<num; k++)
		{
			check[num] = 0;
		}

		if (num == 2)
		{
			count++;
		}
		for (j=j; j<num; j++) 
		{
			if (check[j] == 1)
				continue;
			
			count++;

			int l;		
			for (l=2; l * j < num; l++)
			{				
				check[j * l] = 1;
			}			
		}
		printf("%d\n", count);
		free(check);
	}

	return 0;
}

C++: #include<iostream>
#include<math.h>
main(){int i,j,n,p[1000000];std::cin>>n;for(i=2;i<=n;i++)p[i]=1;for(i=2;i<n;i++)if(p[i])for(j=2;i*j<=n;j++)p[i*j]=0;j=0;for(i=2;i<=n;i++)j+=p[i];std::cout<<j<<std::endl;}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define N 500000
using namespace std;

int main(){

  int n;
  int a,b,i;
  int sosu[N];
  bool judge;

  sosu[0] = 2;
  for(a=3,i=1;a<1000000;a++){
    judge = true;
    for(b=0;sosu[b]*sosu[b] <= a;b++){
      if(a%sosu[b] == 0){
	judge = false;
	break;
      }
    }
    if(judge){
      sosu[i] = a;
      i++;
    }
  }
  while(cin >> n){
    for(i=0;sosu[i]<=n;i++);
    cout << i << endl;
  }

  return 0;
}

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

int main(){
	int n;
	while(cin>>n){
		int manko = 0;
		for(int i = 2; i <= n; i++){
			int ans = 1;
			for(int j = 2; j <= i/j ; j++){
				if(i % j == 0){
					ans += j + i/j;
				}
				if(i == j*j)ans -= j;
			}
			if(ans == 1) manko++;
		}
		cout << manko << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    const int N = 1000000;

    static bool P[N];
    for (int i=2; i<N; i++)
        P[i] = true;
    for (int i=2; i<N; i++)
        if (P[i])
            for (int j=i+i; j<N; j+=i)
                P[j] = false;

    static int A[N];
    for (int i=1; i<N; i++)
        A[i] = A[i-1] + int(P[i]);

    int n;
    while (cin>>n)
        cout<<A[n]<<endl;
}

C++: #include<stdio.h>
using namespace std;
const int maxn=1e6+1;
int prime[maxn];
int main(){
	for(int i=2;i*i<=maxn;i++){
		if(!prime[i]){
			for(int j=2*i;j*j<=maxn;j+=i)
			prime[j]=1;
		}
	}
	int n,flag;
	while(scanf("%d",&n)!=EOF){
		flag=0;
		for(int i=2;i<=n;i++)
		if(!prime[i])
		flag++;
		printf("%d\n",flag);
	}
	return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>

#define N 1000000L
bool num[N];

void furui(void){
  long int i;
  int divide;
  int rt = 1000;
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0L] = false;
  num[1L] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = (long int) divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0;(c = getchar()) != EOF ;i++){

      if(c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    if(c == EOF) break;
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == true) count++;
    }
    std::cout << count << std::endl;
  }
  return 0;
}

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

int CountPrime(int n){
	
	if ((n == 0) || (n == 1)){
		return 0;
	}else{
		std::vector<bool> data(n - 1, 1);
		int count = 0;

		for (int i = 2; i <= n; i++){
			if (data[i - 2] == 1){
				for (int j = i * 2; j <= n; j += i){
					data[j - 2] = 0;
				}
			}
		}
		for (int i = 0; i < n - 1; i++){
			if (data[i] == 1){
				count++;
			}
		}

		return count;

	}
}


int main(){
	int n;

	while (std::cin >> n){
		std::cout << CountPrime(n) << "\n";
	}

	return 0;
}

C++: #include<stdio.h>

int main()
{
	int n,m;
	while(scanf("%d",&n) !=EOF)
	{
		m=0;
		for(int x=2;x<=n;x++)
		{
			for(int y=x-1;y;y--)
			{
				if(y==1)
				{
					m++;
				}
				else if(x%y==0)
				{
					break;
				}				
			}
		}
		printf("%d\n",m);
	}
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <iterator>

#include <cmath>

int main(void){
	using namespace std;

	map<int,int> input_dic;
	list<int> input;
	int k;

	while(cin >> k){
		input.push_back(k);
		input_dic[k] = 0;
	}

	int k_max = ( input_dic.rbegin() )->first;
	vector<bool> sieve(k_max, false);

	int sq_k_max = sqrt(k_max);
	for (int x=1; x<=sq_k_max; ++x) {
		for (int y=1; y<=sq_k_max; ++y) {
			int n = 4*x*x + y*y;
			if ( n<=k_max && (n%12==1 || n%12==5) ){
				sieve[n] = !sieve[n];
			}
			n = 3*x*x + y*y;
			if ( n<=k_max && n%12==7 ){
				sieve[n] = !sieve[n];
			}
			n = 3*x*x - y*y;
			if ( x>y && n<=k_max && n%12==11 ){
				sieve[n] = !sieve[n];
			}
		}
	}
	for (int n=5; n<=sq_k_max; ++n){
		if (sieve[n]){
			for (int k=n*n; k<=k_max; k+=n*n){
				sieve[k] = false;
			}
		}
	}
	sieve[2] = sieve[3] = true;

	int primeCount = 0;
	auto sieveItr = sieve.begin();
	for( auto itr=input_dic.begin(); itr!=input_dic.end(); itr++){
		for( ; distance(sieve.begin(),sieveItr) <= itr->first; sieveItr++){
			if( *sieveItr ){
				primeCount++;
			}
		}
		itr->second = primeCount;
	}

	for(auto itr=input.begin(); itr!=input.end(); itr++){
		cout << input_dic[*itr] << endl;
	}

}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>

#define INF 999999
using namespace std;

int main()
{
	int n;
	
	while (cin >> n)
	{
		int ans = 0,rootn;

		int a[INF] = {0};
		
		rootn = sqrt(n)+1;
	
		for (int i = 2; i <= rootn; i++)
		{
			if (a[i]==0)
			{
				for (int j = i+1; j <= INF; j++)
				{
					if (a[j] == 0 && j%i == 0)
					{
						a[j] = 1;
					}
				}
			}
		}
		cout << "a" << endl;
		for (int i = 2; i <= n; i++)
		{
			if (a[i]==0)
				++ans;
		}
		cout << ans << endl;
	}
			
	return 0;
}

C++: #include<stdio.h> int prime[1000000]; int main(){ prime[0]=-1; prime[1]=-1; for(int i=2;i<1000000;i++){ if(prime[i]==0){ prime[i]=1; for(int j=i*2;j<1000000;j+=i)prime[j]=-1; } } int now; while(~scanf("%d",&now)){ int ans=0; for(int i=1;i<now+1;i++)if(prime[i]==1)ans++; printf("%d\n",ans); } }

C++: /*
P135
AOJ 0009 Prime Number
Difficult: 2
*/

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
#include <cmath>

using namespace std;

const int MAXN = 999999;
int prime[MAXN + 1], pn;
int mindiv[MAXN + 1];

void GetPrime(int n)
{   //determin each num (that <= n) is prime or not.
    //and get primes into an array with pn elements
    //mindiv[i] == i means it is a prime
    fill(mindiv, mindiv+n+1, 0);
    pn = 0;
    for(int i=2; i<=n; ++i){
        if(mindiv[i] == 0) mindiv[i] = i, prime[pn++] = i;
        for(int p=0; p<pn && i*(long long)prime[p] <= n; ++p){
            mindiv[prime[p]*i] = prime[p];
            if(prime[p] == mindiv[i]) break;
        }
    }
}


int main()
{
    GetPrime(MAXN);
    int n;
    while(scanf("%d", &n) !=EOF){
        int x = upper_bound(prime, prime + pn, n) - prime;
        printf("%d\n", x);
    }

}