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++: //0009 Prime Number
//100¢Ì³Ì®nªüÍ³ê½Æ«AnÈºÌfª¢­ç é©oÍ·évOðì¬¹æ
//s²ÆÉêÂÌ®nªüÁÄ¢é@EOFªüÍÌIíèÅ é

#include<iostream>
#include<bitset>
using namespace std;

int main(void)
{
	const int N = 1000000;	//100ÂmÛ
	bitset<N> isPrime;
	int n;
	int i, j;

	while( cin >> n)
	{
		//â¿ðg¢Ü·
		isPrime.set();
		isPrime[0] = isPrime[1] = false;
		for(i = 2; i <= n; i++)
		{
			if(isPrime[i])
			{
				for(j = 2*i; j <= n; j+=i)
				{
					isPrime[j] = false;
				}
			}
		}

		int count = 0;
		for(i = 0; i <= n; i++)
			if(isPrime[i])
				count++;

		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>

int main() {
	// Prime Data Set
	char p[1000000] = {0};
	p[1] = 1;
	for( int i=2; i<1000; i++) if(!p[i]) for( int j=i+i; j<1000000; j+=i) p[j] = 1;
	
	int n;
	int sum;
	while( std::cin >> n) {
		sum = 0;
		for( int i=1; i<n; i++) {
			if(!p[i]) sum++;
		}
		std::cout << sum << std::endl;
	}
}

C++: 
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#include <map>
#define INF 100000
using namespace std;
typedef long long int ll;

int main(){
    vector<ll> era(10000000,0);
    for (int i=1; i<era.size(); i++) {
        era[i]=i;
    }
    for (int i=2; i<era.size(); i++) {
        if (era[i]!=0) {
            ll q = i + era[i];
            while (q<era.size()) {
                era[q]=0;
                q += era[i];
            }
        }
    }
    int n;
    while (cin >> n) {
        int ans=-1;
        for (int i=1; i<=n; i++) {
            if (era[i]==i) {
                ans++;
            }
        }
        cout << ans <<endl;
    }
}

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,max;
	int count[N_MAX];
	bool so[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		so[i]=true;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	so[0]=so[1]=0;
	for(soi=0,i=2;i<=1000;i++){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=false;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include<cstdio>

long prim[1000100];
long prima[1000100];
    
int main() {
    long n, i, x = 0;
    for (i = 2; i <= 1000000; i++) {
        prim[i] = i;
    }
    for (i = 2; i <= 1000000; i++) {
        if (prim[i] != 0) {
                  prima[x] = prim[i];
                  x+= 1;
                  int j = i;
                  while ( j <= 1000000) {
                        prim[j] = 0;
                        j+= i;
                  }
        }
    }
    while (scanf("%ld", &n) != EOF) {
          long a = 0;
          while ( prima[a] <= n) {
                a++;
          }
          printf("%ld\n", a);
    }
    return 0;
}

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

/*??????????????¨?????¢??°       */
/*????????????0????????\????????¨???*/
void print_rist(char *rist, int num){
	int i = 2;
	
	while(i <= num) {
		if (rist[i] != 0) {
			printf("%d ", i);
		}
		i++;
	}
	printf("\n");
}


main(){
	char rist[1000001];
	int i, j;
	int input_num = 0;
	int count;
	int ans;
	
	/*??????????????§????´???°????±???????????????\???*/
	for(j = 0; j < 30; j++) {
		scanf("%d", &input_num);
		if (input_num == EOF) {
			break;
		}
		/*??¢?´¢??????????????????*/
		for (i = 1; i <= input_num; i++) {
			rist[i] = 1;
		}	
		rist[i] = 0;
		rist[1] = 0;
		/*?´???°??????????????????*/
		count = 2;
		while((count * count) <= input_num) {	/*???input_num??????????????§*/
			i = 2;
			/*count??\??????count????????°??????????????¨???*/
			while((i * count) <= input_num) {
				rist[i * count] = 0;
				i++;
			}
			count++;
			/*?¬????count?????????*/
			while(rist[count] != 1) {
				count++;
			}
			
		}
		
		ans = 0;
		for (i = 1; i <= input_num; i++) {
			if (rist[i] == 1) {
				ans++;
			}
		}
		printf("%d\n", ans);
		//print_rist(rist, input_num);
	}
	return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;
  int num;
  int i,flag,count;

  while(scanf("%d",&n)!=EOF) {

    count=0;

    for(num=1;num<=n;num++) {

      flag=1;

      for(i=2;i<num;i++) {
	if(num%i==0) {
	  flag=0;
	  break;
	}
      }
      
      if(num==1) flag=0;

      if(flag==1) { 
	count++;
      }
    }

    printf("%d\n",count);

  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>

using namespace std;
typedef long long Int;
#define REP(i , x) for(int i = 0 ; i < x ; ++i)

typedef pair<int, int> P;

bool dp[10000100];

int main()
{
	int N;
	while (cin >> N){
		long ans(0);
		dp[0] = dp[1] = true;
		for (int i = 2; i <= N*N; ++i){
			if (!dp[i]){
				for (int j = 2*i; j <= N; j += i)
					dp[j] = true;
			}
		}
		for (int i = 2; i <= N; ++i){
			ans += !dp[i];
		}
		cout << ans << endl;
	}
}

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

int main(){
	int num, cou, i, j, flag;
	
	while(cin >>num){
		cou = 0;
		for(i = 3; i < num; i+= 2, flag = 0){
			for(j = 3; j < sqrt(num); j += 2){
				if(i % j == 0){
					flag = 1;
					break;
				}
			}
			if(flag == 0) cou++;
		}
		cout <<cou + 2<<endl;
	}
	
	return 0;
}

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

int main(){
	int m=0,n;
	cin>>n;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
	return 0;
}

C++: #include <stdio.h>

int main(){
	int sosuu[] = { 2, 3, 5 }, i, x, y = 3,n=0,z;
	
	while (scanf("%d", &n)!=EOF){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0)break;
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int tmp;
	while (cin >> tmp)
	{
		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		prime.clear();
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

const int MAX = 1000000;
int N;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    vector<bool> is_prime(MAX,true);
    vector<int> prime(MAX,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i < MAX; ++i){
        if(is_prime[i]){
            for(int j = i*2; j < MAX; j += i) is_prime[j] = false;
        }
    }

    for(int i = 1; i < MAX; ++i){
        prime[i] = prime[i-1] + is_prime[i];
    }

    while(cin >> N){
        cout << prime[N] << '\n';
    }
    return 0;
}