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 <cmath>
#include <algorithm>

using namespace std;

void Eratosthenes(vector<int> &S_List, vector<int> &P_List){
	while(1){
		vector<int>::iterator it = S_List.begin();
		P_List.push_back(*it);  //先頭を素数リストへ追加
		int num = *it;
		while (it != S_List.end()){
			if ((*it % num) == 0){
				it = S_List.erase(it); //探索リストから倍数を除外
			}
			else{
				++it;
			}
		}
		vector<int>::iterator P_it = max_element(P_List.begin(), P_List.end());
		double p_max_sqr = sqrt(*P_it);
		vector<int>::iterator S_it = max_element(S_List.begin(), S_List.end());
		if (S_List.empty() == true){
			return;
		}
		if (*S_it < p_max_sqr){
			return;
		}
		/*else{
			Eratosthenes(S_List, P_List);
		}*/
	}
}


void output(vector<int> ex){
	/*vector<int>::iterator it = ex.begin();
	while(it != ex.end()){
		cout << *it << endl;
		++it;
	}*/
	cout << ex.size() << endl;
}

int main(void){
	int num;
	while (cin >> num){
		vector<int> S_List, P_List;
		for (int i=2; i<=num; ++i){
			S_List.push_back(i);
		} 
		Eratosthenes(S_List, P_List);
		output(P_List);
	}
	return 0;
}

C++: #include <iostream>
#define N 100000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int cnt=0,res=0;
    for(int i=2; i<=n; i++){
      for(int j=1; j<=n; j++){
        if(i%j == 0) cnt++;
        if(cnt > 2) break;
      }
      if(cnt==2) res++;
      cnt = 0;
    }
    cout << res << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
inline bool prime(int x){
	for(int i=2;i<x;i++)
		if(!(x%i))	return false;
	return true;
}
int main(){
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++)
			if(prime(i))	ans++;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,S;
while(cin>>n)
{
	S=0;
	if(n==1)
	{
		cout<<0<<endl;
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=i-1;j>1;j--)
		{
			if(i%j==0)
			{
				break;
			}
			if(j==2)
		{
			S++;
		}
		}	
			
	}
	cout<<S<<endl;
}
return 0;
}

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

int main(void){
  int n;
  while(cin >> n){
    int nums[n];
    int prime=0;
    for(int i=1;i<=n;i++){
      nums[i]=i;
    }
    for(int i=1;i<=n;i++){
      if(nums[i]>1){
	prime++;
	for(int j=2;nums[i]*j<=n;j++){
	  nums[nums[i]*j]=1;
	}
      }
    }
    cout << prime << endl;
  }
  
  return 0;
}

C++: //{Headers
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<queue>
#include<deque>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp(x,y) make_pair(x,y)
typedef long long ll;
//}

const int MAXN=1e6;
int N,nPrime[MAXN];

bool isPrime[MAXN];
void EratosthenesSeive(){
    memset(isPrime,true,sizeof isPrime);
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<MAXN;i++) if(isPrime[i]){
        for(int j=i<<1;j<MAXN;j+=i)
            isPrime[j]=false;
    }
}

void init(){
    EratosthenesSeive();
    nPrime[0]=0;
    for(int i=1;i<MAXN;i++) nPrime[i]=nPrime[i-1]+(isPrime[i]?1:0);
}

void solve(){printf("%d\n",nPrime[N]);}

int main(void){
//    freopen("in.txt","r",stdin);
    init();
    while(~scanf("%d",&N))
        solve();
    return 0;
}

/*
Sample Input
10
3
11
Output for the Sample Input
4
2
5
*/

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

int main(){
	int n=0,i,g,k,count=0,keta[6],result,wa3=0,wa4=0,wa8=0;
	double x,y;
	bool p=false;
	while(scanf("%d",&n)==1){
	for(x=0;x<6;x++){
		i=x;
		result=pow(10,x);
		keta[i]=n%result;
	}
	for(i=0;i<6;i++){
		wa3+=keta[i];
		if(i<1) wa4+=keta[i];
		if(i<2) wa8+=keta[i];
	}
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(i>n/2+1){
				if(wa3%3==0) break;
				if(wa4%4==0) break;
				if(wa8%8==0) break;
				if(n % i ==0){
				 p=true;
				 break;
				}
			}
			else if(g % i == 0){
				p=true;
				break;
			}
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	wa3=0;
	wa4=0;
	wa8=0;
	}
	return 0;
}

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

int main()
{
	const size_t MAX = 1000000;

	bitset<MAX> primebox;
	primebox.set();
	primebox.reset(0);
	primebox.reset(1);

	for(int i = 2; i < MAX; i++)
	{
		if(!primebox.test(i))
			continue;

		for(int j = i*2; j < MAX; j += i)
			primebox.reset(j);
	}

	size_t n;
	while(cin >> n)
	{
		int found;
		if(n < 2)
			found = 0;
		else if(n == 2)
			found = 1;
		else
		{
			found = 1;
			for(size_t i = 3; i <= n; i += 2)
				if(primebox.test(i))
					found++;
		}

		cout << found << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
#define MAX_NUM 999999


void do_calc(int *numPrime){
  for(int i=2;i<=MAX_NUM;i++){
    bool flag = false;

    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0){
	flag = true;
	break;
      }
    }
      
    if(flag){
      numPrime[i] = numPrime[i-1];
      continue;
    }else{
      numPrime[i] = numPrime[i-1] + 1;
    }
  }
}
  


int main(){
  int n;
  int numPrime[MAX_NUM];

  do_calc(numPrime);
  while(cin >> n){
    cout << numPrime[n] << endl;
  }
}

C++: #include<stdio.h>
bool b[4000000];

int main(void)
{
    int a,n,i;
    int count=0;
    int f=1;

    for(i=3;i<4000000;i+=2){
        f=1;
        for(a=2;a*a<=i;a++){
            if(i%a == 0){
                f=0;
                break;

            }
        }
        if(f==1){
            b[i]=1;
        }
    }
    b[2]=1;

    while(scanf("%d",&n)!=EOF){
        for(i = 0; i < n; i++){
            if(b[i]==1)count++;
        }

    printf("%d\n",count);
    count=0;
    }
    return 0;
}