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<iostream>
#include<vector>
#include<algorithm>

using namespace std;
const int N=1000000;
vector<bool> pr(N,true);
vector<int> p;

void init()
{
	int i,j;
	p.reserve(80000);
	p.push_back(2);
	for(i=3;i*i<N;i+=2)
		if(pr[i]) {
			p.push_back(i);
			for(j=i;i*j<N;j+=2) pr[i*j]=false;
		}
	for(;i<N;i+=2) if(pr[i]) p.push_back(i);
}

int main()
{
	int n;
	init();
	while(cin>>n) {
		cout<<upper_bound(p.begin(),p.end(),n)-p.begin()<<endl;		
	}
	return 0;
}

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

struct theSieveOfEratosThenes {
	vector<bool> prm;

	theSieveOfEratosThenes(int n) {
		prm = vector<bool>(n + 1, true);
		prm[0] = prm[1] = false;
		for (int i = 2; i * i <= n; ++i) {
			if (prm[i]) {
				for (int j = 2 * i; j <= n; j += i) prm[j] = false;
			}
		}
	}

	bool isPrimeNumber(int a) {
		return prm[a];
	}
};

int main() {
	int n;
	theSieveOfEratosThenes tsoet(999999);
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (tsoet.isPrimeNumber(i)) ++ans;
		}
		cout << ans << endl;
	}
}

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

		getline(cin, &tmpstr);

		tmp = atoi(tmpstr.c_str());

		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;

		//if (cin.eof()) { break; }
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define out cout 
#define in cin
#define el endl

#define rep(i, N) for (int i = 0; i < N; i++)
#define mito(N) cout << N << endl

bool f[1000001] = {false};

int main()
{
	for (int i = 2; i * i < 1000001; i++){
		for (int j = i * i; j < 1000001; j += i){
			f[j] = true;
		}
	}

	int n;
	while (in >> n){
		int c = 0;
		for (int i = 2; i <= n; i++){
			if (!f[i])c++;
		}
		mito(c);
	}

	return (0);
}

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

using namespace std;

#define max 999999 + 1

int main(void){

	vector< bool > table( max, true );
	vector< int > p( max, 0 );
	table[0] = false;
	table[1] = false;

	for( int i = 2; i < max; i++ ) {
		if( table[i] == false ) continue;
		for( int j = 2 * i; j < max; j+=i ) {
			table[j] = false;
		}
	}

	for( int i = 1; i < max; i++ ) {
		p[i] = p[i - 1] + table[i];
	}

	int n;
	
	while( scanf("%d", &n ) != EOF ) {
		cout << p[n] << endl;
	}

    return 0;
}

C++: /*
Volume0-0009
*/
#include <iostream>
#include <stdlib.h>
#include <string.h>

#define N 1000000
#define TRUE (int)(0==0)
#define FALSE !TRUE

using namespace std;

int main(int argc, char *argv[]){
  int f[N];

  //  memset(f, TRUE, N);
  f[0]=FALSE;
  f[1]=FALSE;
  for (int i=2; i<N; i++)
    f[i] = TRUE;

  for (int i=2; i<N; i++){
    if (f[i] == TRUE ) {
      for (int j=i+i; j<N; j+=i){
	f[j] = FALSE;
      }
    }
  }
  int n;
  while (cin >> n) {
    int m = 0;
    for (int i=1; i<=n; i++){
      if (f[i]){
	m++;
      }
    }
    cout << m << endl;
  }
 
  exit(0);
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	int a[1000000];
	a[0]=1;
	a[1]=1;
	for(int i=2;i<1000000;i++){
		if(a[i]==0){
			for(int j=i;j<1000000;j+=i){
				a[j]=1;
			}
		}
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<b;i++){
			if(a[i]>b)break;
			else {
				if(a[i]==1) c++;
			}
		}
		cout<<c<<endl;
	}
}

C++: #include<stdio.h>
int count = 0;
int IsPrime(int n){//試し割り
	int i;
	if(n < 2)
		return 0;
		
	else if(n==2){
		count++;
	}
	
	if(n % 2==0)
		return 0;
		
	for(i = 3; i * i <= n; i+=2)
		if(n % i == 0)
			return 0;
			
	count++;
}
int main(){
	int i;
	scanf("%d",&i);
		while(1){
			IsPrime(i);
			i--;
			if(i == 0){
				printf("%d\n",count);
				break;
			}
		}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#define STA 1000000
using namespace std;

bool prime[STA];

int main(){
    memset(prime,true,sizeof(prime));
    for(int i=2;i<STA/2;i++){
        for(int j=2;i*j<STA;j++) prime[i*j] = false;
    }
    int n;
    while(cin >> n){
        int cnt = 0;
        for(int i=2;i<=n;i++){
            if(prime[i]) cnt++;
        }
        cout << cnt << endl;
    }
}

C++: #include <stdio.h>

int main(void){
    int n;
    int cnt;
    int prm;

    while (scanf("%d", &n)!= EOF){
        cnt = 0;
        for(int i=2; i<=n; i++){
            prm=1;
            for (int j=2; j*j<= i; j++){
                if (i%j==0){
                    prm=0;
                    break;
                }
            }
            cnt+=prm;
        }
        printf("%d\n", cnt);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
int main(int argv,int* argv[]){
unsigned x[30];
int count=0;
for(int i=0;i<argv;i++){
cin>>x[i];
}
for(int i=0;i<argv;i++){
for(int j=1;j<x[i];j++){
if(x[i]%j!=0)
count++;
}
cout<<count<<endl;
count=0;
}
return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin>>n){
		int ans=0;
		std::vector<int> vec(n+1);
		for(int i=0;i<=n;i++)vec[i]=1;
		vec[0]=vec[1]=0;
		for(int i=2;i<=n;i++){
			if(vec[i] == 1){
				ans++;
				for(int j = 2 * i ; j <= n ; j += i){
					vec[j]=0;
				}
			}
		}
		std::cout<<ans<<std::endl;
	}

	return 0;
}

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

using namespace std;

#define NUM_LIMIT 1000000   // numbers < NUM_LIMIT

int getNumOfPrimes(bitset<NUM_LIMIT> &isPrime, int last_limit, int limit){
    int cnt = 0;
    for (int i = 2; i <= limit; i++){
        if (!isPrime[i]) continue;  // skip non prime numbers
        cnt ++;
        // cross out the multiples of the number
        for (int j = max(2.0,ceil((double)last_limit/i)); i*j <= limit; j++){
            isPrime[i*j] = 0;
        }
    }
    return cnt;
}

int main(){
    //ifstream cin("input.txt");
    bitset<NUM_LIMIT> isPrime;
    isPrime.set();  // set all bits to 1
    
    // input data
    int number;
    int max_num = 0;
    while(cin >> number){
        int cnt = 0;
        if (number > max_num){
            cnt = getNumOfPrimes(isPrime, max_num+1, number);
            max_num = number;
        } else {
            cnt = getNumOfPrimes(isPrime, number+1, number);
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main(void){
  int n;
  while(cin >> n){
    if(n < 3){
      if(n < 2){
	cout << 0 << endl;
      }else{
	cout << 1 << endl;
      }
    }
    for(int i = 3; i <= n; i += 2){
      bool flag = true;
      for(int j = 3; j <= sqrt(i); j += 2){
	if(i % j == 0){
	  flag = false;
	}
      }
      if(flag)
	ans++;
    }
    cout << ans << endl;
  }
  return 0;
}