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 <cmath>
using namespace std;

int main(){
    int n, cnt;
    bool prime[1000000] = {false, false};

    for(int i = 2;i < 1000000;i++){
        prime[i] = true;
    }
    
    for(int i = 2;i <= sqrt(1000000);i++){
        if(prime[i]){
            for(int j = 2*i;j <= 1000000;j++){
                if(j%i == 0){
                    prime[j] = false;
                }
            }
        }
    }
    
    while(cin >> n){
        cnt = 0;

        for(int i = 2;i <= n;i++){
            if(prime[i]){
                cnt++;
            }
        }
        
        cout << cnt << endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

bool is_prime(int n) {
        if (n < 2) {
                return false;
        }

        int max = n / 2;
        int i;
        for (i=2; i < max; i++) {
                if (n % i == 0) {
                        return false;
                }
        }

        return true;
}

int number_of_primes_under(int n) {
        if (n < 2) {
                return 0;
        }

        int count = 1;
        int i;
        for (i=3; i <= n; i = i + 2) {
                if (is_prime(i)) {
                        count++;
                }
        }

        return count;
}
int main(void) {
        int n;
        while(cin >> n) {
                cout << number_of_primes_under(n);
                cout << endl;
        }

        return 0;
}

C++: #include <iostream>
using namespace std;
bool prime[1000000];
void sieve() {
    fill_n(prime, 1000000, true);
    for (int i=2; i<=1000; ++i) {
        if (prime[i]) {
            for (int j=i*i; j<1000000; j+=i) {
                prime[j] = false;
            }
        }
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    sieve();

    int memo[1000000];
    for (int i=1; i<1000000; ++i) {
        memo[i] = memo[i-1]; 
        if (prime[i]) {
            memo[i] ++; 
        }
    }

    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i=2; i<=n; ++i) {
            if (prime[i]) {
                cnt ++;
            }
        }
        cout << cnt << "\n";
    }
    return 0;
}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<iostream>
#include<cmath>
using namespace std;

int main(){
    int n;
    while(~scanf("%d", &n)){
        int cnt = 0;
        for(int i = 3; i<=n; i+=2){
            int k= 0;
            for(int j=3; j<sqrt(i); j+=2){
                if(i%j==0){
                    k=1;
                    break;
                }
            }
            if(k==0) cnt++;
        }
        printf("%d\n", cnt);

    }

    return 0;
}

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

int main(void){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}
return 0;
}

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

// chack wheather a number n is a natural number
bool checkNaturalNum(int n) {
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    if (n % i == 0) {
      count++;
    }
  }

  if (count == 2) {
    return true;
  } else {
    return false;
  }
}

int countNaturalNum(int n) {
  int count = 0;
  for (int i = 1; i < n + 1; i++) {
    if (checkNaturalNum(i)) {
      count++;
    }
  }
  return count;
}

int main(int argc, char const *argv[]) {
  int num;
  while (std::cin >> num) {
    std::cout << countNaturalNum(num) << '\n';
  }
  return 0;
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 0;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 0;
		
		for (int i = 1;i<=num;i++) {
		if(i%2==0) {
			//cout <<"2: "<<i<<endl;
			count ++;
			continue;
		}
		for (int j=3;j<i;j=j+2) {
			if (i%j==0) {
				count ++;
				//cout <<"i: "<<i<<" j: "<<j<<endl;
				break;
			}
		}
	}
	cout << (num-count) <<endl;
	//cout << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
typedef long long int LL;
#define MOD 1000000007

LL pow(LL m, LL n)
{
	LL res = 1,x = 1,a = m;
	while (x <= n) {
		if ((x & n) > 0) {
			res *= a;
			res %= MOD;
			a %= MOD;
		}
		a *= a;
		x <<= 1;
	}
	res %= MOD;
	return res;
}

int main()
{
	LL m, n;
	cin >> m >> n;
	cout << pow(m,n) << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  vector<int> v;
  while (cin >> n) {
    if (v.size() >= n + 1) {
      cout << accumulate(v.begin(), v.end() - (v.size() - (n + 1)), 0) << endl;
      continue;
    }
    v.resize(n + 1);
    fill(v.begin(), v.end(), 1);
    v[0] = 0;
    v[1] = 0;
    for (int i = 0; i * i < v.size(); ++i) {
      while (v[i] == 0) ++i;
      for (int m = i + 1; m < v.size(); ++m) {
        if (m % i == 0) {
          v[m] = 0;
        }
      }
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}

C++: /*
题意：给定整数 n， 请问 n 以内有多少个素数？
思路：如果对许多整数进行素性测试，则采用 埃氏筛法 （枚举 n 以内的素数，辗转相除）
		埃氏筛法：辗转相除：
			首先，将 2 到 n 范围内的所有整数写下来。其中最小的数字 2 是素数。将表中所有 2 的倍数都划去。
			表中剩余的最小数字是 3，它不能被更小的数整除，所以是素数。再将表中所有 3 的倍数都划去。
			以此类推，如果表中剩余的最小数字是 m 时，m就是素数。然后将表中所有 m 的倍数都划去。 
			像这样反复操作，就能依次枚举 n 以内的素数。 
*/

#include <iostream>
#include <stdio.h>
using namespace std;
#define MAX_N  999999

int prime[MAX_N];		// 第 i 个素数 
bool is_prime[MAX_N];	// is_prime[i] 为 true 表示 i 为素数 

// 返回 n 以内素数的个数 
int sieve( int n )
{
	int p = 0;
	for( int i = 0; i <= n; i++ )
		is_prime[i] = true;
	
	is_prime[0] = is_prime[1] = false;
	
	for( int i = 2; i <= n; i++ )
	{
		if( is_prime[i] )
		{
			prime[p++] = i;
			for( int j = 2 * i; j <= n; j += i )
				is_prime[j] = false;				
		}	
	}
	return p;
} 

int main()
{	
	int s;
//	while (cin  >>  s)
	while (scanf("%d", &s) != EOF) 
	{
		cout << sieve(s) << endl;
	}	
	return 0;
}

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

int main()
{
	int count=0,n;

	while(cin>>n)
	{
		int prime[1000001]={0};
		prime[0]=1;
		prime[1]=1;
		for(int i=2;i<=sqrt(n);i++)
			if(prime[i]==0)
				for(int j=i+1;j<=n;j++)
					if(i%j==0)
						prime[j]=1;
		for(int i=2;i<=n;i++)
			if(prime[i]==0)
				count++;
		cout<<count<<endl;
		count=0;
	}
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e6+5,maxm=1e5+5;
int fac[maxn],pri[maxm],siz;
int a[maxn];
void euler(){
	int i,j;
	siz=0;
	for (i=0;i<maxn;i++) fac[i]=i;
	for (i=2;i<maxn;i++){
		if (fac[i]==i) pri[siz++]=i;
		for (j=0;j<siz&&pri[j]<=fac[i]&&i*pri[j]<maxn;j++)
			fac[i*pri[j]]=pri[j];
	}
}
int main(){
	int i,n;
	euler();
	a[0]=a[1]=0;
	for (i=2;i<maxn;i++)
		a[i]=a[i-1]+(fac[i]==i);
	while (scanf("%d",&n)!=EOF)
		printf("%d\n",a[n]);
	return 0;
}