Go: package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	//"math"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		fmt.Println(calc(n))
	}
}

func calc(n int)int{
	// エラトステネスで数え上げる
	// 最初から999999まで用意しておいて入力のたびO(1)で出すのとどっちが速いのかはわからん
	eratos := make([]bool, n+1)
	c := 0
	for i:=2; i<len(eratos); i++{
		if eratos[i] == false{
			c++
			for j:=i*i; j<len(eratos); j+=i{
				eratos[j]=true
			}
		}
	}
	return c
}

func next()string{
	return sc.Text()
}

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    static bool isprime[1000001];
    isprime[2]=true;
    for(int i=3; i<1000000; i+=2) isprime[i]=true;
    for(int i=3; i<1000; i+=2){
        if(!isprime[i]) continue;
        int d=i+i;
        for(int j=i+d; j<1000000; j+=d)isprime[j]=false;
    }
    int n;
    while(cin>>n){
        int ans=0;
        for(int i=2; i<=n; ++i) if(isprime[i]) ++ans;
        cout<<ans<<'\n';
    }
    return 0;
}

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

int main()
{
	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=0; i<1000000; i++){
		is_prime[i]=true;
	}
	
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<1000000; j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n_prime[1000000];

	int cnt=0;
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i]=cnt;
	}

	while(true){
		int n;
		cin>>n;

		if(cin.eof())
			break;
	
		cout<<n_prime[n]<<endl;
	}
	
	return 0;
}

C++: #include<iostream>
 
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

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

int main(){
  int a;
  int i, j, k;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        k=past/i;
        for(j=k; j<=a/i; j++){
          chk[j*i]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

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

#define maxPN 1000000
#define PNs  1000100
int countPN = 0, countPNs = 0;
int PrimeNum[maxPN], temp;
bool PN[PNs];

bool IsPrimeNumber(int x);

void PrimeN(){
	int i, j;
	PrimeNum[0] = 2;
	PN[2] = true;PrimeNum[countPN++] = 2;
	PN[3] = true;PrimeNum[countPN++] = 3;
//	PN[5] = true;PrimeNum[countPN++] = 5;
	
	for(i = 6; i  < PNs;i+=6){
		if(IsPrimeNumber(i-1)){
			PrimeNum[countPN++] = i-1;
			PN[i-1] = true;//cout<<i-1<<endl;
		}
		if(IsPrimeNumber(i+1)){
			PrimeNum[countPN++] = i+1;
			PN[i+1] = true;//cout<<i+1<<endl;
		}
		countPNs = i+1;//cout<<i-1<<" "<<PN[i-1]<<endl;
	}
}

bool IsPrimeNumber(int x){
	//if(x == 2 || x == 3) return true;
	//if(x <= 4 || x%2 == 0 || x%3 == 0)   return false;
	//if(x < countPNs) return PN[x];
	for(int i = 0; PrimeNum[i] * PrimeNum[i] <= x; i++)
		if(x%PrimeNum[i] == 0)return false;
	return true;
}


int main(){
//	clock_t start, end;
	int n = true, counta;
//	start = clock();
	PrimeN();
//	cout<<PrimeNum[countPN-1]<<" "<<countPNs<<endl;
//	cout<<clock()-start<<"ms"<<endl;
	
	while(cin>>n){
		counta = 1;
		
		
		//cout<<(IsPrimeNumber(n)?"yes":"no")<<endl;
	//	start = clock();
		//cout<<IsPrimeNumber(n)<<endl;
		for(int i = 1; i <= n; i+=2){
			if(PN[i])counta++;
		//	cout<<i<<" "<<PN[i]<<endl;
		}
		if(n == 1) counta = 0;
		cout<<counta<<endl;
	//	cout<<clock()-start<<"ms"<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
    int n,num[999999] = {0},i,j,ans;

    while(cin >> n){
        ans = 0;
        for(i = 0;i <= n;i++){
            num[i] = 1;
        }

        for(i = 2;i <= sqrt(n);i++){
            if(num[i]){
                for(j = 0;i * (j + 2) <= n;j++){
                    num[i * (j + 2)] = 0;
                }
            }
        }

        for(i = 2;i <= n;i++){
            if(num[i]){
                ans++;
            }
        }

        cout << ans << endl;
    }
    
    return 0;
}

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

int main()
{
	int n;
	vector<int> prime;

	while (cin >> n) {
		prime.push_back(2);

		for (int I = 2; I <= n; I++) {
			bool isPrime = true;
			for (int i = 0; i < prime.size(); i++) {
				if (I%prime[i] != 0)
					isPrime = false;
			}
			if (isPrime)
				prime.push_back(I);
		}
		cout << prime.size() << endl;
		prime.clear();
	}
	return 0;
}

C++: /*
http://blog.csdn.net/liuke19950717
*/
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn= 999999+5;
ll prime[maxn];
int main()
{
	ll cnt=0;
	for(ll i=2;i<maxn;++i)
	{
		if(!prime[i])
		{
			prime[i]=++cnt;
			for(ll j=i*i;j<maxn;j+=i)
			{
				prime[j]=1;
			}
		}
		else
		{
			prime[i]=prime[i-1];
		}
	}
	ll n;
	while(~scanf("%lld",&n))
	{
		printf("%lld\n",prime[n]);
	}
	return 0;
}

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

using namespace std;

const int MAX_N=999999;

bool prime[MAX_N+1];
int p[MAX_N+1];

int main(){
	fill(prime,prime+MAX_N+1,true);
	for (int i=2;i<=MAX_N;i++){
		if (prime[i]){
			for (int j=2*i;j<=MAX_N;j+=i){
				prime[j]=false;
			}
		}
	}
	p[1]=0;
	for (int i=2;i<=MAX_N;i++){
		p[i]=p[i-1]+(prime[i] ? 1 : 0);
	}
	int n;
	while (cin>>n){
		cout<<p[n]<<endl;
	}
	return 0;
}

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

int main() {
	bool isPrime[1000000] = {true};

	for (int i = 0; i < 1000000; i++) {
		isPrime[i] = true;
	}

	cout << endl;
	isPrime[1] = false;
	for (int i = 2; i < 1000000; i++) {
		if (!isPrime[i])
			continue;
		/*
		for (int j = 2; j <= i/j; j++) {
			if (i%j == 0) {
				isPrime[i] = false;
				break;
			}
		}
		*/
		if (isPrime[i]) {
			int k = 2*i;
			while (k < 1000000) {
				isPrime[k] = false;
				k += i;
			}
		}
	}

	int n;
	while (cin >> n) {
		int sum = 0;
		for (int i = 2; i < n; i++) {
			if (isPrime[i])
				sum++;
		}
		cout << sum << endl;
	}

	return 0;
}

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

C++: #include<stdio.h>
int prime[1000000];
int main(){
    prime[0]=-1;
    prime[1]=-1;
    for(int i=2;i<1000000;i++){
        if(prime[i]==0){
            prime[i]=1;
            for(int j=i*2;j<1000000;j+=i)prime[j]=-1;
        }
    }
    int now;
    while(~scanf("%d",&now)){
        int ans=0;
        for(int i=1;i<now+1;i++)if(prime[i]==1)ans++;
        printf("%d\n",ans);
    }
}

C++: #include <iostream>
using namespace std;
 
 
int main()
{
    int max = 10000;
    int prime[max];
    
    fill(prime, prime + max, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < max; i++) {
        if (prime[i]) {
            for (int j = 2*i; j < max; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for(int i = 1;i < max; i++){
	    prime[i] = prime[i] + prime[i-1];
    }
    
    int aaa;
    while (cin >> aaa) {
	cout << prime[aaa] << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
bool num[1000000]={true,true};
int main(){
  for(int i=2; i<1000; i++)
    if(!num[i])
      for(int j=i*i; j<1000000; j+=i)
	num[j] = true;
  int n;
  while(cin >>n){
    int ans = 0;
    for(int i=2; i<=n; i++)
      if(!num[i]) ans++;
    cout <<ans<<endl;
  }
  return 0;
}