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>
#include <cmath>
using namespace std;

int a[1000000];

int sosuu(){
	a[0] = 0;
	a[1] = 0; 
	int k;
	for(int i = 2;i<1000000;i++){
		k = 0;
		a[i] = a[i - 1];
		for(int j=2;j<=sqrt(i);j++){
			if(i%j == 0){
				k++;
				break;
			}
		}
		if(k==0){
			a[i]++;
		}
	}
	return 0;

}

int main(){
	int n;
	sosuu();
	while (true)
	{
		cin >> n;
		if (cin.eof()) { break; }
		cout << a[n] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include<stdio.h>
#include<string>
#include<map>
#include<vector>
#include<stdlib.h>
typedef long long ll;
using namespace std;
#define INF 100000000000
#include<algorithm>
#include<string.h>
bool num[1000000];
int main(){
    int n;
    while(cin >> n){
        memset(num,true,sizeof(num));
        num[0] = num[1] = false;
        for(int i = 2;i<=n;i++){
            if(num[i] == true){
                for(int j = 2*i;j<=n;j+=i){
                    num[j] = false;
                }
            }

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

}

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

using namespace std;

int HowManyPrimeNumbers1(const int);
int HowManyPrimeNumbers2(const int);
int MySqrt(const int);

int main(){
	int n;

	while(cin >> n){
		printf("%d\n",HowManyPrimeNumbers2(n));
	}

	return 0;
}

int HowManyPrimeNumbers1(const int n){
	int i,j,buf,cnt = 1;

	for(i=3;i<=n;i+=2){
		buf = (int)sqrt((double)i);

		for(j=3;j<=buf;j+=2){
			if((i % j) == 0){
				cnt--;
				break;
			}
		}

		cnt++;
	}

	return cnt;
}

int HowManyPrimeNumbers2(const int n){
	int i,j,cnt,root,rt;

	// 3 から n までの奇数の個数 + 1 を n に代入
	cnt = ((int)((((double)(n - 2)) / 2) + 0.5)) + 1;

	// 最大処理数を求める
	root = (int)sqrt((double)n);

	// a
	for(i=3;i<=root;i+=2){
		rt = MySqrt(i);
		for(j=3;j<=rt;j+=2){
			if((i % j) == 0){
				cnt += ((int)(n / i));
				break;
			}
		}
		cnt -= ((int)(n / i));
	}

	return n;
}

int MySqrt(const int i){
	int n;

	n = i - 1;

	return (int)(1 + (1 / 2) * (double)(i - 1) - (1 / 8) * (double)(i - 1) * (i - 1) + (1 / 16) * (double)(i - 1) * (i - 1) * (i - 1));
}

C++: #include <iostream>
#include <cmath>
using namespace std;
#define MAX 1000000

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt((double)MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

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

C++: #include <cstdio>
#define max_n 999999
#define INF 1000000
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        prime[i] = INF;
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        //printf("%d\n",n);
        int ans = 0;
        for(int i =0; i<max_n; i++){
            if(prime[i]>n){
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

int main() {
  constexpr int max = 1000000;
  vector<bool> isPrime(max, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < max; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < max; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;

	while(cin >> n){
		count = 1;
		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j * j <= i; j += 2){
				if(i % j == 0){
					flag = true;
					break;
				}
			}
			if(flag != true){
				count++;
			}
			else{
				flag = false;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: //求n以内素数个数以及所有素数
//复杂度O(n*loglogn)
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
const int MAXN = 1000000+5;

int prime[MAXN]; //第i个素数
bool is_prime[MAXN+1]; //is_prime[i]为true表示i是素数，否则不是

//返回n以内素数个数
int seive(int n){
    int p=0;
    for(int i=0;i<=n;++i) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;++i){
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}

bool is_prime_large[MAXN]; // is_prime_large[i-a]=true <--> i是素数
//求区间[a,b)之间的素数及个数, a<b<=10^12, b-a<=10^6
int segment_sieve(ll a, ll b){
    seive((int)sqrt(b)+1);
    for(int i=0;i<b-a;++i) is_prime_large[i]=true;

    for(int i=2;(ll)i*i<b;++i){
        if(is_prime[i]){
            for(ll j=max(2LL,(a+i-1)/i)*i; j<b; j+=i) is_prime_large[j-a]=false;
        }
    }

    int p=0;
    for(ll i=a;i<b;++i){
        if(is_prime_large[i-a]) p++; 
    }
    return p;
}

int main(){
/*    ll a=22801763489, b=22801787297;*/
    //int p=segment_sieve(a,b);
    //cout<<"segment_sieve:"<<p<<endl;

    int n;
    while(cin>>n) {
        cout<<seive(n)<<endl;
    }
}

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

#define MAX 1000000

int main(){
	int i,j,k;
	bool n[MAX];
		i=MAX; while(i--) n[i]=true;

	while(~scanf("%d", &i)){

	for(j=2; j<i; j++){
		if(n[j]==true){
		for(k=2; j*k<i; k++){
			n[j*k]=false;
		
		}
		}
	}

	for(j=2, k=0; j<i; j++) if(n[j]==true) k++;

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

C++: #include <iostream>
using namespace std;
int main() {
  long n;
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    int x = 1;
    if (n == 2) {
      cout << x << endl;
      continue;
    }
    x++;
    for (int i = 3; i <= n; i += 2)
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) break;
        if ((j + 1) * (j + 1) > i) x++;
      }
    cout << x << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int max = 1000100;
	bool prime[1000100];
	int dp[1000100];
	prime[0] = prime[1] = false;
	int ret=0;
	memset(prime,true,sizeof(prime));
	memset(dp,0,sizeof(dp));
	int hako[30];
	memset(hako,0,sizeof(hako));
	REP(i,30) cin >> hako[i];
	for(int i=2;i<sqrt(max);i++)for(int j=i*2;j<max;j=j+i){
		prime[j] = false;
	}
	for(int i=1; i<max ;i++){
		dp[i]=dp[i-1];
		if(prime[i])dp[i]++;
	}
	REP(i,30)	cout << dp[hako[i]] << endl;
	return 0;
}

C++: #include<iostream>
#define N 1000000
using namespace std;
void PrimeNum(int n,bool Primeif[]){
  for(int i = 2;i*i < n;i++){
    if(Primeif[i] == true){
      for(int k = 2;k * i < n;k++){
	Primeif[k*i] = false;
}
    }
  }
}
int main(){
  int n,num;
  bool Primeif[N+1];
  Primeif[1] = false;
  for(int i = 2;i < N;i++){
    Primeif[i] = true;
  }
  PrimeNum(N+1,Primeif);
  
  while(cin >> n){
    num = 0;
    for(int i = 0;i <= n;i++){
      if(Primeif[i] == true){
	num = num+1;
      }
    }
     cout << num << endl;
     
   } 
    
}