Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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

int main() {
  vector<bool> isPrime(MAX, true);
  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 2; i * i < MAX; i++) {
    if (isPrime[i]) {
      for (int j = 2; i * j < MAX; j++) {
        isPrime[i * 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 <complex>
using namespace std;

int main(){
    int ans,n,i,k;
	while(1){
		ans=0;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			cout<<0<<endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=9){
				for(i=9;i<=n;i+=2){
				    int prime=1;
				    for(k=3;k<=sqrt(i);k+=2){
					    if(k==3||k%3!=0){
					        if(i%k==0){
						            prime=0;
						            break;
					        }
    					}
					}
				    if(prime)ans++;
				}
			}
		cout<<ans<<endl;
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;



int erat(int num){
int i,cnt=1;
//	vector<int> Prime(num+2); // 素数リスト
	if(num<2) return 0;
	vector<char> Find(num+2); // 探索リスト
	for(int i = 2; i <= num; i++) Find[i] = '0';
	for(int i = 2; i*i < num; i++){
    	if(Find[i] > '0') continue; // すでに除いた数は飛ばす

    // j++からj+=iになったのでループ内でiの倍数のみが処理される。だいぶ高速化
    	for(int j = i * 2; j< num; j += i) {
        	if(Find[j]=='0') Find[j] = '1';
    	}
	}
// 2の倍数の素数は2だけなので奇数のみを判定
//	Prime.push_back(2);
//	for(int i = 3; i*i < num; i += 2){
//    	if(Find[i]='0') Prime.push_back(i);
//	}
	rep2(i,3,num) if(Find[i]=='0' && i % 2) { cnt++;}
	return cnt;
}

int main(void){

int num;

	while(cin >> num){
//		cnt = erst(num);
		cout << erat(num) <<endl;
	}
	return 0;
}

C++: #include<stdio.h>
int num[999999]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=999999;i++)
	num[i]=1;
for(int i=2;i<=1001;i++){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

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

const long MAX_N=10000000;
bool isPrime[MAX_N];

int main(){
	//素数テーブルの設定
	for(long i=2; i<=MAX_N; ++i)
		isPrime[i]=true;
		
	for(long i=2; i<=MAX_N; ++i){
		if(isPrime[i]){
			for(long j=2; i*j<=MAX_N; ++j) isPrime[i*j]=false;
		}
	}
	
	//実際の問題処理
	long n;
	
	while( scanf("%ld", &n) != EOF ){
		long count=0;
		
		for(long i=2; i<=n; ++i){
			if(isPrime[i]) ++count;
		}
		
		printf("%ld\n", count);
	}	 

	return 0;
}

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

int N;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    vector<bool> is_prime(1000000,true);
    vector<int> prime(1000000,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i <= 1000000; ++i){
        if(is_prime[i]){
            ++p;
            for(int j = i*2; j <= 1000000; j += i) is_prime[j] = false;
        }
        prime[i] = p;
    }

    for(int i = 0; i <= 30; ++i){
        cin >> N;
        cout << prime[N] << '\n';
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int isprime(int x){
    if(x==2||x==3) return true;
    if(x<5||x%2==0||x%3==0) return false;
    else{
        int i=5;
        while(i<=sqrt(x)){
            if(x%i==0) return false;
            i = i+2;
        }
        return true;
    }
}
int main() {
    int n;
    while(cin >> n){
        int ans=0;
        for (int i=2; i<=n; i++) {
            if (isprime(i)!=0) {
                ans++;
            }
        }
        
    cout << ans << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
 
 
// cin >>
// cin <<
bool isPrime(int x){
    if(x==2) return true;
    if(x<2||x%2==0) return false;
    int i=3;
    while(i<=sqrt(x)){
         if (x%i==0)return false;
        i= i+2;
    }
    return true;
}
int main(){
    int in[30]={};
    int out=0;
	int max=0;
	bool flag[10000];
    for(int i=0;i<30;i++){
		cin >>in[i];
		if(i==0){
			max=in[i];
		}else{
			if(in[i]>max){
				max=in[i];
			}
		}
	}
	for(int j=0;j<max;j++){
		if(isPrime(j)==true){
			flag[j]=true;
		}else{
			flag[j]=false;
		}
    }
	
    for(int i=0;i<30;i++){
		out=0;
		for(int j=0;j<in[i];j++){
			 if(flag[j]==true){
				 out++;
			 }
		}
		if(out!=0){
       	cout <<out <<endl;
		}
    }
     
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[1000000];
    int n;
    a[0]=2;
    int k=1;
while(cin>>n){
    for(int i=3;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<k<<endl;
    k=1;
 }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long int ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	vi v(1000010, 1);
	vi copy(1000011, 1);
	ll n, c = 0;
	double rt;

	v[0] = 0;

	while (cin >> n){
		rt = sqrt(n);
		FOR(i, 1, rt){
			if (v[i] == 1){
				for (int j = i + 1; (i + 1)*j <= n; j++){
					v[(i + 1)*j - 1] = 0;
				}
			}
		}
		REP(i, n){
			if (v[i] == 1)c++;
		}
		cout << c << "\n";
		c = 0;
	}
}

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

int main() {
	int n, count;
	bool *data;

	while (cin >> n) {
		data = new bool[n+1];
		count = 0;
		data[0] = data[1] = false;
		for (int i = 2;i <= n;i++) {
			if (data[i]) {
				count++;
				for (int j = i + j;j <= n;j += j) {
					data[j] = false;
				}
			}
		}
		cout << count << endl;
		delete[] data;
	}
	return 0;
}

C++: #include <math.h>
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <string>

#define YES "YES"
#define NO "NO"
#define space ' '

using namespace std;

void func();

int main(void)
{
	
	func();

	return 0;
}


#define MAXIMUM 1000000
bool table[MAXIMUM];
int cnt[MAXIMUM];
#define not true
#define prime false
void func()
{
	table[0] = not;
	table[1] = not;
	for (int i = 2; i < MAXIMUM; i++)
	{
		if (table[i] == prime)
		{
			for (int j = i * 2; j < MAXIMUM; j += i)
			{
				table[j] = not;
			}
		}
	}
	for (int i = 1; i < MAXIMUM; i++)
	{
		if (table[i] == prime)
		{
			cnt[i] = cnt[i - 1] + 1;
		}
		else
		{
			cnt[i] = cnt[i - 1];
		}
	}

	int n;
	while (cin >> n, !cin.eof())
	{
		cout << cnt[n] << endl;
	}

}