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 <fstream>

using namespace std;

void init(int *m) {
    m[1] = 0;
    m[2] = 1;
    for (int i = 3; i <= 1000000; i += 2)
        m[i] = 1;

    for (int i = 3; i <= 1000; i += 2) {
        if (m[i] == 0)
            continue;
        for (int j = 2; i * j <= 1000000; j++)
            m[i * j] = 0;
    }

    for (int i = 3; i <= 1000000; i++)
        m[i] += m[i-1];
}

int main() {

    #if 0
        ifstream cin("34870.in");
    #endif

    int *memo = new int[1000001];
    init(memo);

    int n;
    while (cin >> n) {
        cout << memo[n] << endl;
    }

    return 0;
}

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

//??¨??????????????????????????§?´???°??¨?????????
//?´???°??¨??¨?´???????????????£?????????????????§??¨????????????

const int MAX_V = 10000000;
int prime[MAX_V + 1]; //?´???°??¨
int sum[MAX_V + 1]; //?´???°?????°???????¨?

int main()
{
	int i, k, v;
	prime[0] = prime[1] = 0;
	for (i = 2; i <= MAX_V; i++)
	{
		prime[i] = 1;
	}
	for (i = 2; i*i <= MAX_V; i++)
	{
		if (prime[i])
		{
			for (k = 2 * i; k <= MAX_V; k += i)
			{
				prime[k] = 0;
			}
		}
	}

	sum[0] = 0;
	for (i = 0; i < MAX_V + 1; i++)
	{
		sum[i+1] = sum[i] + prime[i+1];
	}

	int input;
	while (cin >> input)
	{
		cout << sum[input] << endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int sang(int n,bool *s,int *p,int &m){
	m = 0;
	for(long i = 2; i<=n;i++){
		s[i] = 2;
	}
	for(long i = 2; i<=n; i++){
		if(s[i]){
			p[m++] = i;
			for(long j = i * i; j<= n ; j += i){
				s[j] = 0;
			}
		}
	}
	return m;
}
int main(){
	int test =0;
	bool s[100005];
	int n,p[100005],m;

	while(test <=30){
		cin>>n;
		sang(n,s,p,m);
		cout<<m<<endl;
		test++;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
        int n;
        int d; //素数を入れるための添字
        bool count; //割りきれるかどうかの判定
        int number[400000]; //素数を入れておく
        number[0] = 2;
        
        
        while(cin >>n != 0){
                d = 0;
                for(int i = 3; i <= n; i++){
                        count = true;
                        for(int j = 0; j <= d; j++){
                                if(i % number[j] == 0){
                                        count = false;
                                }
                        }
                        if(count == true){
                                d++;
                                number[d] = i;
                        }
                }
        cout << d+1 << endl;
        }
        return 0;
}

C++: #include<cstdio>
using namespace std;
bool us[1000000]={false};
int p[1000000] = {0};
int main(){
	/*Eratosthenes*/
	p[0] = 2;
	for(int i = 0; i <= 1000000; i+=2){
		us[i] = true;
	}
	
	int cnt = 1;
	for(int i = 3; i <= 1000000; i+=2){
		int q = 0;
		if(us[i] == true)continue;
		else if(us[i] == false){
			p[cnt] = i;
			cnt++;
			us[i] = true;
			q = i;
			for(int j = q+q; j <= 1000000; j += q){
				us[j] = true;
			}
		}
	}
	
	int n;
	while(~scanf("%d",&n)){
		int x = 0;
		while(1){
			if(p[x] > n)break;
			x++;
		}
		printf("%d\n",x);
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void init(){
	for(int i=2;i<999999;i++){
		bool isprime=true;
		for(vector<int>::iterator p(prime.begin());p!=prime.end();p++){
			if(p*p>i)break;
			if(i%*p==0){
				isprime=false;
				break;
			}
		}
		if(isprime){
			prime.push_back(i);
		}
	}
}
int main(){
	int n;
	init();
	while(cin>>n){
		cout<<lower_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[100000]={0};
	for(int i=2;i<100000;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0)flag=false;
		}
		if(flag){
		sosu[cnt]=i;
		cnt++;
		}
	}
	while(cin>>n){
	ans=0,cnt=0;
	for(int i=2;i<=n;i++){
		if(sosu[cnt]==i){
			cnt++;
			ans++;
		}
	}
	cout<<ans<<endl;
	}
    return 0;
}

C++: #include<iostream>
#include<vector>

using namespace std;
   
void primeCal()
{
    const int N = 1000000;
    
    vector<bool> prime(N, true);
    
    prime[0] = prime[1] = false;
    
    for (int i = 2; i*i < N; ++i) 
    {
        if (!prime[i]) 
        { 
            continue; 
        }
        
        for (int j = i*i; j < N; j += i) 
        {
            prime[j] = false;
        }
    }
    
    vector<int> count(N);
    
    for (int i = 1; i < N; ++i) 
    {
        count[i] = count[i-1] + prime[i];
    }
    
    int n;
    
    while (cin>>n)
    {
        cout << count[n] << endl;
    }
    
    return;
}
     
int main()
{     
    primeCal();
    return 0;
}

C++: #include <iostream>
#include <math.h>
#define N 1000000
using namespace std;


bool sosu_hantei(int num){
int i;
for(i=2;i<=sqrt((double)num);i++){
if(num%i==0)return false;
}

if(num==4)return false;

return true;

}

int main(){
int n,i,count=0;
bool sosu[N];

for(i=0;i<N;i++){

sosu[i]=sosu_hantei(i);
}

while(cin >> n){

for(i=2;i<=n;i++){
if(sosu[i]){ 
count++;
}
}

cout << count << endl;
i=2;count=0;
}

}