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<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 1000000;
int prime[MAXN + 1];
void getPrime()
{
    memset(prime, 0, sizeof(prime));
    for (int i = 2; i <= MAXN; i++)
    {
        if (!prime[i])
        {
            prime[++prime[0]] = i;
        }
        for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++)
        {
            prime[prime[j] * i] = 1;
            if (i % prime[j] == 0)
            {
                break;
            }
        }
    }
}
int main()
{
	getPrime();
	int n,sum;
	while(~scanf("%d",&n)){
		sum=0;
		for(int i=1;i<MAXN;i++){
			if(prime[i]<=n){
				sum++;
			}else{
				break;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int i,j,ch[1000000];

    for(i=0;i<1000000;i+=2){ch[i]=0;ch[i+1]=1;}

    ch[1]=0;
    ch[2]=1;

    for(i=3;i<1000;i+=2) if(ch[i]) for(j=i<<1;j<1000000;j+=i) ch[j]=0;

    for(i=3;i<1000000;i++) ch[i]+=ch[i-1];

    while(cin>>i) cout<<ch[i]<<endl;

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
//#define local
//if you find any bug in my code, please tell me.
const int N=1e6+10;
bool prime[N];
int ans[N];
void init()
{
    prime[0]=prime[1]=false;
    for(int i=2; i<=N; i++)
        prime[i]=true;
    int cnt=0;
    for(int i=2; i<=N; i++)
    {
        if(prime[i])
        {
            cnt++;
            for(int j=2*i; j<=N; j+=i)
                prime[j]=false;
        }
        ans[i]=cnt;
    }
}
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    init();
    int n;
    while(~scanf("%d",&n))
    {
        printf("%d\n",ans[n]);
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <ctime>
 
using namespace std;
 
int main()
{
    int n;
    vector<int> prime;
     
    //unsigned long t = time(NULL);
    prime.push_back(2);
	prime.push_back(3);
    while (scanf("%d", &n) != EOF){
		if (prime[prime.size() - 1] <= n){
			for (int i = prime[prime.size() - 1] + 2; i <= n; i += 2){
				bool p = true;
				for (int j = 0; prime[j] <= i / 2; j++){
					if (i % prime[j] == 0){
						p = false;
						break;
					}
				}
				if (p){
					prime.push_back(i);
				}
			}
		}
		
		int count;
		for (count = 0; count < prime.size() && prime[count] <= n; count++){
			;
		}
		printf("%d\n", count);
    }
     
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool array[1000500];
		for(int i=0;i<=n;i++){
			array[i]=true;
		}

		int count=0;
		array[0]=array[1]=false;
		for(int i=1;i<=n;i++){
			if(array[i]){
				count++;
				for(int j=i*2;j<=n;j+=i){
					array[j]=false;
				}
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int count;
	//int maxin=0;
	c[0]=c[1]=0;
	for(i=2;i<100000;i++){
		c[i]=1;
	}

	while((scanf("%d",&n)!=EOF)&&(n!=0)){
		/*if(n>maxin){
			maxin=n;
		}*/
		count=0;

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

		printf("%d",count);


	}





	return 0;
}

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

using namespace std;

int main() {

	int n,count;

	while (cin >> n) {
		count = 0;
		
		//?´???°????????????????¨???¶?????????????????????????¢????
		bool *is_prime;
		is_prime = (bool *)malloc(n+1);
		if (is_prime == NULL) {
			cout << "malloc error" << endl;
			break;
		}

		//????????¨????´???°??§????????¨??????
		for (int i = 0; i <= n; i++) {
			is_prime[i] = true;
		}

		for (int i = 2; i <= n; i++) {
			//?´???°???????????§????????£???????????????????????§??????
			if (is_prime[i] == true) {
				//????????°???????????§????????°????????£?????????
				for (int j = i+1; j <= n; j++) {
					//cout << "i=" << i << " j=" << j << " is_prime(i)=" << is_prime[i] << " is_prime(j)=" << is_prime[j] << endl;
					if (is_prime[j] == true) {
						if (j%i == 0) {
							//????????????????????????????´???°??§?????????
							is_prime[j] = false;
						}
					}
				}
			}
		}

		//?´???°??¨?¢????????????°????????°????????????
		for (int i = 2; i <= n; i++) {
			if (is_prime[i] == true) {
				count++;
				//cout << " " << i;
			}
		}

		//??¨???
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
//#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
inline int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

C++: #define _USE_MATH_DEFINES
#include <iostream> 
#include <math.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std; 
int main(){
	int N;
	while (cin >> N){
		int p=log2(N);
		cout << N*p << endl;
	}
	return 0;
}

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

const int ARR_MAX = 1000000;
int fl[ARR_MAX];
int sm[ARR_MAX+1] = {0};

void init_arr();
void isfl(int);

int main(void) {
  int tag;
  init_arr();

  while(1){
    cin >> tag;
    if(tag == 0 || cin.eof()) break;
    isfl(tag);
    cout << sm[tag] << endl;
  }
  return 0;
}

void init_arr(){
  for(int i=0;i<ARR_MAX;i++) fl[i] = 1;
}

void isfl(int tag){
  int i,lim,idx = 2;
  fl[0] = 0;
  fl[1] = 0;

  lim = sqrt(tag);

  while(idx <= lim){
    if(fl[idx] == 1) for(i = idx*2;i<=tag;i+=idx) fl[i] = 0;
    idx++;

  }
  for(int i = 2;i<=tag;i++) sm[i] = sm[i-1] + fl[i];
  return;
}

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

#define rep(i,n) for(int i=2; i<=n; i++)
bool isprime(long long int n){
	rep(i,sqrt(n)){
		if(n%i==0) return false;
	}
	return true;
}
int main(){
	long long int n, ans;
	while(cin >> n){
		ans=0;
		rep(i,n) if(isprime(i)) ans++;
		cout << ans << endl;
	}
    return 0;
}