Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include<cstdio>
#include<cmath>
#define SIZE 1000000
#define sizE 1000000

int prime[sizE], nprime=0;
int mark[SIZE];

void sieve()
{
    int i,j, limit=sqrt(SIZE*1.0)+2;

    mark[0]=1;
    mark[1]=1;

    for(i=4; i<=SIZE; i+=2)
        mark[i]=1;

    prime[nprime]=2;

    for(i=3; i<=SIZE; i+=2)
    {
           if(!mark[i])
            {
            prime[++nprime] = i;

            if(i<=limit)
            {
                for(j=i*i; j<=SIZE; j+=i*2)
                mark[j]=1;
            }
        }
    }

}

int main()
{
    int n;

    sieve();

    while(scanf("%d", &n)==1)
    {
        int i,k;
        i=k=0;

        while(i++<n)
        {
            if(!mark[i])
            k++;
        }

        printf("%d\n", k);
    }

    return 0;
}

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

int main()
{
	bool is_prime[1000000];
	memset(is_prime,false,sizeof(is_prime));
	for(int i=2;i<1000000;i++){
		if(!is_prime[i]){
//			cout<<i<<endl;
			for(int m=i*2;m<1000000;m+=i){
				is_prime[m]=true;
			}
		}
	}
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(!is_prime[i]) ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int i = 0, maxV = INT_MIN, A[30] = {};
	for (int k; cin >> k; ) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	int s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0, j;
	for (int k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			for (j = 2; j * k < s; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n[100000],j,o=0;
	for(int i=2;i<=99999;i++){
		n[i]=1;
		
	}
	n[0]=n[1]=0;
		for( j=2;j<=99999;j++){
			if(n[j]){
				for(int k=j*2;k<=9999;k+=j){
				n[k]=0;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
		}
}

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;
}