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<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n,ans;

int main(){
    int N=1000000;
    int prime[N];
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
    while(cin>>n){
        ans=0;
        rep(i,n+1)ans+=prime[i];
        out(ans);
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,cnt=0,ans,sosu[1000003]={0};
	
	for(int i=2;i<1000002;i++){
		bool flag=true;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0){
			flag=false;
			break;//素数でない時点で打ち切り
			}
		}
		/*if(flag){
		cnt++;
		sosu[i]=cnt;
		}*/
		if(flag)cnt++;
		sosu[i]=cnt;		
	}
	//for(int i=0;i<31;i++)cout<<sosu[i]<<" ";
	while(cin>>n){
	cout<<sosu[n]<<endl;
	}
    return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int x,prime=0,count=0;
    
    cin >> x;
    
    for (int j=1; j<=x; j++)
    {
        for (int i=1; i<=x; i++)
        {
            if(j%i==0)
              count+=1;
        }
        if (count==2)
           prime+=1;
        
        count=0;
    }
    
     cout << prime;  
        
    return 0;    
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i <=MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i+i; j*j <=MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}

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

int main(){
	bool prime[1000001];
	for(int i = 0; i < 1000001; i++) prime[i] = true;
	prime[0] = false;
	prime[1] = false;
	for(int i = 2; i < 1000; i++){
		for(int j = i*2; j < 1000; j += i){
			prime[j] = false;
		}
	}

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

C++: #include <iostream>
#include <vector>
#include <set>
#include <cmath>
std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 1000000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
  return 0;
}

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

int main(){
	bool p[1000000];
	int num[1000000];
	int c,n;
	
	for(int i=0;i<1000000;i+=2)p[i] = false ;

	for(int i=1;i<1000000;i+=2)p[i] = true ;
	
	p[1] = false;
	p[2] = true;
	
	c=3;
	while(c < 1000){
		for(int i=3*c; i < 1000000; i+=2*c)p[i] = false;
		do{c+=2;}while(!p[c]);
	}
	
	c=0;
	for(int i = 0 ; i < 1000000 ; i++){
		if(p[i])c++;
		num[i] = c;
	}
	
	while(cin>>n)cout<<num[n]<<endl;
}

C++: #include<stdio.h>

int pr[50847534];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
        /*printf("O\n");*/
      return nxp;
    }else{
        /*printf("X\n");*/
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF){
        printf("n=%d\n",n);
        i=0;
        if(n-1){
            while(pr[i]<=n){
                /*printf("prime:%d(%d)\n",pr[i],i+1);*/
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
    }
}

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

typedef long long LL;
using namespace std;

const int X = 1000001;
bool isPrime[X];

void init(){
  for(int i=0;i<X;i++){
    isPrime[i] = false;
  }
  isPrime[2] = true;
  for(int i=3;i<X;i+=2){
    cout << i << endl;
    bool ok = true;
    for(int j=2;j<=sqrt(i);j++){
      if(!isPrime[j])continue;
      if(i%j==0)ok=false;
    }
    if(ok)isPrime[i] = true;
  }
}

int main(){
  init();
  int n;
  while(cin >> n){
    int answer = 0;
    for(int i=0;i<n+1;i++){
      if(isPrime[i])answer++;
    }
    cout << answer << endl;
  }
  return 0;
}