Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

int main() {
  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> ans(N);
  for (int i = 1; i < N; ++i) {
    ans[i] = ans[i - 1] + prime[i];
  }
  int n;
  while (cin >> n) {
    cout << ans[n] << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	static bool prim[1000010]; rep(i,1000010)prim[i]=true;
	static int ans[1000010];
	ans[1]=0;
	
	int i=2;
	for(;i*i<=1000000;i++){
		ans[i]=ans[i-1];
		if(prim[i]){
			ans[i]++;
			for(int j=i*i;j<=1000000;j+=i){
				prim[j]=false;
			}
		}
	}
	for(;i<=1000000;i++){
		ans[i]=ans[i-1];
		if(prim[i])ans[i]++;
	}
	
	int n;
	while(~scanf("%d",&n))printf("%d\n",ans[n]);
}

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

const int MAX_N = 1000000;

vector<int> init(void){
    vector<int> prime;
    bool is_prime[MAX_N];
    memset(is_prime, true, MAX_N);
    
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<MAX_N; i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i; j<MAX_N; j+=i) is_prime[j] = false;
        }
    }
    return prime;
}

int main(int argc, const char * argv[])
{
    int n;
    vector<int> prime = init();
    while(cin>>n){
        cout << upper_bound(prime.begin(), prime.end(), n)-prime.begin() << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    int prime_num[1000001];
    memset(prime_num, 0, 1000001);
    prime_num[2] = 1;
    int ans = 1;
    for(int i = 3; i <= 1000000; i++) {
        if(i % 2 == 0) { 
            prime_num[i] = prime_num[i-1];
            continue;
        }
        bool is_prime = true;
        for(int j = 3; j*j <= i; j++) {
            if(i % j == 0) {
                is_prime = false;
                break;
            }
        }
        if(is_prime) {
            prime_num[i] = prime_num[i-1] + 1;
        } else {
            prime_num[i] = prime_num[i-1];
        }
    }
    int n;
    while(cin >> n) {
        cout << prime_num[n] << endl;
    }
    return 0;
}

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

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = i;i*j < 1000000;j++){
			c[i*j] = true;
		}
		}
		t[i]=t[i-1]+!c[i];
	}
	for(int n;cin>>n;n++){
		cout << t[n] << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long;

const int MAXN = 1000000;

int tot; bool vis[MAXN];
int prime[MAXN];

void init() {
    for(int i = 2; i < MAXN; ++i) {
        if(!vis[i]) prime[tot++] = i;
        for(int j = 0; j < tot; ++j) {
            if(i*prime[j] >= MAXN) break;
            vis[i*prime[j]] = true;
            if(i%prime[j] == 0) break;
        }
    }
}

int main() {
    init();
    int n;
    while(~scanf("%d", &n)) {
        printf("%d\n", upper_bound(prime, prime+tot, n) - prime);
    }
    return 0;
}

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

class CheckList{
public: 
    int candidateNumber;
    bool isPrime;
public:
    CheckList();
    CheckList(int number);
};

CheckList::CheckList(int number){
    candidateNumber = number;
    isPrime = true;
}

CheckList::CheckList(){
    candidateNumber = 0;
    isPrime = true;
}

int main(){
    int n;
    while(cin >> n){
        vector<CheckList> list(n-1);
        for(int i=2;i<=n;++i){
            CheckList number(i);
            list[i-2] = number;
        }
        for(int i=2;i<=sqrt(n);++i){
            if(!list[i-2].isPrime){
                continue;
            }
            for(int j=i;j<=n;++j){
                if(j%i == 0 && i != j){
                    list[j-2].isPrime = false;
                    continue;
                }
            }
        }
        for(vector<CheckList>::iterator it = list.begin();it!=list.end();){
            if(!(*it).isPrime){
                it = list.erase(it);
                continue;
            }
            it++;
        }
        cout << list.size() << endl;
    }
}

C++: #include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int prime(int x) {
    int ret = 0;
	for(int i = x; i > 1; i--) {
		int n = (int)sqrt(i);
		int yakusu = 0;
		for(int j = 1; j<=n; j++) {
			if(i%j==0) yakusu++;
		}
		if (yakusu==1) {
			ret++;
		}
	}
	return ret;
}

int main(){
    int x;
    while(cin>>x){
        cout << prime(x) << 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 = 0;
		for(int i = 1; i <= n; i++){
			if(i < 2);
			else if(i == 2){
				count++;
			}
			else if(i % 2 != 0){
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
					}
				}
				if(flag != true){
					count++;
				}
			}
			flag = false;
		}

		cout << count << endl;
		

	}

	return 0;
}

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

int main(){
	int n=0,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)==1){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0) p=true;
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	}
	return 0;
}

C++: #include <cstdio>
int d[1000000],c[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<=999999;i++) {
		if(d[i]){c[i]=r;continue;}
		c[i]=++r;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n]);
	}
}