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<iostream>
#include<algorithm>
using namespace std;
bool prime[1000001];
int main(){
	int n;
		prime[1] = true;
		for(int i = 2; i * i <= 1000000; i++){
			if(!prime[i]){
				for(int j = i + i; j <= 1000000; j += i){
					prime[j] = true;
				}
			}
		}
	while(cin >> n){
		int ans = 0;
		for(int i = 1; i <= n; i++){
			if(!prime[i])ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	int n; while(cin >> n){
		int sum = 0;
		for (int i = 1; i < n + 1; i++) {
			if (isprime(i))sum++;
		}
		cout << sum << '\n';
	}
	return 0;
}

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

bool isPrime(int a){
	int x = std::sqrt((double)a);
	for(;x>1;x--)
		if(a%x == 0)
			return false;
	return true;
}

int countPrime(int a){
	int x = a,ans = 1;
	if(x%2==0)
		x--;
	for(; x>1; x-=2)
		if(isPrime(x))
			ans++;
	return ans;
}

int main(){
	int n;
	while(std::cin >> n)
		std::cout << countPrime(n) << std::endl;
	return 0;
}

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

int p[1000010];

int main(){
	int n;
	int count;

	//エラトステネスの篩
	//素数のリストをつくる
	for (int i = 0; i <= 1000000; i++) p[i] = 1;
	p[0] = p[1] = 0;
	for (int i = 2; i*i <= 1000000; i++){
		if (p[i] == 1){
			for (int j = 2; i*j <= 1000000; j++){
				p[i*j] = 0;
			}
		}
	}

	//素数のカウント
	while (cin >> n){
		count = 0;
		for (int i = 0; i <= n; i++){
			if (p[i] == 1)count++;
		}
		cout << count << endl;
	}

	return 0;
}

C++: /*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	int a;
	int count;
	int ccount;
	vector<int> c = { 0 };
	while (cin >> a)
	{
		a = a + 1;
		count = 0;
		/*
		// ?´???°?????????
		// ??????????????°
		for (size_t i = 2; i < a; i++)
		{
			ccount = 0;
			// ????????°
			for (size_t j = 1; j <= i; j++)
			{
				//cout << "i= " << i << "j= " << j << endl;
				if (i % j == 0) {
					ccount++;
				}
			}
			if (ccount > 2) {
				count++;
			}
		}*/
		// ?????§????????§????????????0??§???????????????
		c.resize(a);

		
		// 2*i????????§????????§?????????????????????1?????????
		for (size_t i = 2; i < a; i++)
		{
			for (size_t j = 2; i*j < a; j++)
			{
				//cout << i*j << endl;
				c[i*j] = 1;
			}
		}
		// ??????????????????0??????????????°????????????
		for (size_t i = 0; i < a; i++)
		{
			if (c[i] == 0) {
				count++;
			}
		}
		cout << count-2 << endl;

		// ?¢??????¨
		
		for (size_t i = 0; i < a; i++)
		{
			cout << i << " = " << c[i] << endl;
		}
		
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;



int main(){
	int n; cin >> n;
	vi p(n + 1, 1);
	p[0] = p[1] = 0;
	int ans = 0;
	rep(i, n + 1) if (p[i]) {
		ans++;
		for (int j = i + i; j <= n; j += i) p[j] = 0;
	}
	cout << ans<< endl;
	return 0;
}

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

int main(){
    int n;
    while(cin>>n){
        if(n == 1) {
            cout<<0<<endl;
        }
        else if(n == 2){
            cout<<1<<endl;
        }
        else{
            int num[1000000] = {};
            for(int tmp = 2;tmp != n;tmp++){
                if(num[tmp] == 0)
                for(int i = tmp * 2;i <= n;i += i){
                    num[i] = 1;
                }
            }
            int count = 0;
            for(int i = 2;i != n;i++){
                if(num[i] == 0){
                    count++;
                }
            }
            cout<<count<<endl;
        }
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

int main(){
  int n,ans[1000000]={0};
  bool num[1000000]={true};
  num[1]=true;
  for(int i=2;i<1000000;i++){
    if(num[i]==false){
      for(int j=i+i;j<1000000;j=j+i){
	num[j]=true;
      }
    }
  }

  for(int i=1;i<1000000;i++){
    ans[i]=ans[i-1]+!num[i];
    //cout<<num[i]<<endl;
  }
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  
  return 0;
}

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

bool isChecked[1000010];
vector <int> prime;

int main() {
	for (int i = 0;i < 1000000; i++) isChecked[i] = false;
	isChecked[0] = true;
	isChecked[1] = true;
	for (int i = 2; i < 1000000;i++) {
		if(isChecked[i]) continue;
		prime.push_back(i);
		for (int j = 1; j * i < 1000000;j++) {
			isChecked[j*i] = true;
		}
	}
	int n;
	while(cin >> n) {
		int i;
		for(i = 0;;i++) {
			if (prime[i] > n) break;
		}
		cout << i << endl;
	}
	return 0;
}

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

int main()
{
	vector<int> pcount;
	int prime[10000];
	int j, k, x, num,count=0;
	while (cin >> num){
		prime[0] += 2;
		x = 1;
		k = 1;
		while (prime[k-1] <= num)
		{
			x += 2;
			j = 0;
			while (j < k && x % prime[j] != 0)j++;
			if (j == k)
			{
				prime[k++];
				count++;
			}
		}
		pcount.push_back(count);
		count = 0;
	}
	for (int i = 0; i < pcount.size(); i++)
	{
		cout << pcount[i] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
int main(){
	int a[999999]={0},i,j;
	a[1]=1;
	for(i=2;i<=999999;i++){
		if(a[i]==0)for(int j=i*2;j<=999999;j+=i)a[j]=1;}
	int n;
	while(~scanf("%d",&n)){
		int sum=0;
		for(i=1;i<=n;i++){
			if(a[i]==0)sum++;}
		printf("%d\n",sum);}
	return 0;}