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 <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = 998244353;
const double EPS = 1e-9;

bool s[1000000] = {};
int sosu[1000000] = {};
void erast(){
  memset(s,1,sizeof(s));
  s[1] = false;
  s[0] = false;
  REP(i,2,1000){
    if(s[i]){
      REP(j,2,1000000){
        if(i*j>=1000000) break;
        s[i*j] = false;
      }
    }
  }
  REP(i,2,1000000) sosu[i] = sosu[i-1]+s[i];
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    erast();
    int n;
    while(cin >> n){
      cout << sosu[n] << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int MAX = 1000000;
    int lim = sqrt(MAX);
    vector<int> is_prime(MAX, 1);
    is_prime[0] = is_prime[1] = 0;
    for(int i = 2; i < MAX; ++i) {
        if(is_prime[i])
            if(i < lim) 
                for(int j = i*i; j < MAX; j += i) is_prime[j] = 0;
    }

    vector<int> primes;
    for(int i = 0; i < MAX; ++i)
        if(is_prime[i]) primes.push_back(i);

    int n;
    while(cin >> n) 
        cout << upper_bound(primes.begin(), primes.end(), n)-primes.begin() << endl;
    return 0;
}

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

const int MX = 1000000;
bool prime[MX];
int cnt[MX];

int main() {
    for (int i=0; i<MX; ++i) prime[i] = true;
    prime[0] = prime[1] = false;
    for (int i=2; i<MX; ++i) {
        if ( ! prime[i]) continue;
        for (int j=i; (long long)i*j<MX; ++j) {
            prime[i*j] = false;
        }
    }
    cnt[0] = 0;
    for (int i=1; i<MX; ++i) {
        cnt[i] = cnt[i-1] + prime[i];
    }
    int N;
    while (cin >> N) {
        cout << cnt[N] << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
  int n;
  
  while(1) {
    cin >> n;
    if(cin.eof()) {
      break;
    }
    int m = (int)sqrt(n);
    
    vector<bool> h(n+1, true);
    h[0] = false;
    h[1] = false;
    
    for(int i = 2; i <= m; i++) {
      if(h.at(i)) {
	for(int s = 2; s*i < h.size(); s++) {
	  if(h.at(s*i))
	    h[s*i] = false;
	}
      }
    }
    
    int ans=0;
    for(auto f : h) {
      if(f)
	ans++;
    }
    cout << ans << endl;
  }
  
  return 0;
}

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

using namespace std;

int solist[999999];

int main(int argc, char* argv[])
{
	int num;
	int count;
	int i, j;
	int val;

	count = 8;
	solist[0] = 2;
	solist[1] = 3;
	solist[2] = 5;
	solist[3] = 7;
	solist[4] = 11;
	solist[5] = 13;
	solist[6] = 17;
	solist[7] = 19;

	for (num = 3; num < 1000000; num += 2) {
		for (i = 0; i < count; i++) {
			if (num % solist[i] == 0) break;
		}
		if (i == count) solist[count++] = num;
	}

	while (cin >> val) {
		for (i = 0; i < count; i++) {
			if (solist[i] > val) {
				cout << i + 1 << endl;
				break;
			}
		}
		if (i == count) cout << count << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
const int MAX_N = 1000000; // いくつまで調べるか
bool prime[MAX_N + 1]; // 添字が素数ならtrue、それ以外はfalse
void sieve()
{
  prime[0] = prime[1] = false; // 例外処理
  // 配列prime の初期化
  for(int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  // 素数でないものを調べる
  for(int i = 2; i <= MAX_N; ++i)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
	}

int is_prime(int n)
{
  return prime[n];
  }

/*bool is_prime(int n)
{
  if(n == 1)return false;
  for(int i = 2; i < n; ++i)
    if(n % i == 0)return false;
  return true;
  }
*/
int main()
{
  sieve();
  int a;
  while(cin >> a){
    //cin >> a;
    //if(a==EOF)return 0;
    int count=0;
    //int tmp;
    for(int i=1;i<=a;i++){
      if(is_prime(i))count++;
    }
    printf("%d\n",count);
  }
}

C++: #include<iostream>
using namespace std;
#define L long long int
int main(){
int n,ans,i,j;
while(cin>>n){
	ans=0;
	for(i=2;i<=n;i++){//search for 2 to n
		for(j=2;j<=i;j++)if(i%j==0)break;
		if(j==i)ans++;
	}
	cout<<ans<<endl;
}
return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans=0;
    vector<int> vec;
    vec.push_back(2);
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        vec.push_back(i);
      }
    }
    cout << vec.size() << endl;;
  }
  return 0;
}

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




int main(){


	int Nmax = 1000000;
	bool isp[Nmax]={};
	int count[Nmax]={};

	isp[2] = true;
	for(int i=3;i<Nmax;i+=2){
		isp[i] = true;
	}

	for(int i=3;i<Nmax;i+=2){
		if(isp[i]){
			int j = i*2;
			while(j<Nmax){
				isp[j] = false;
				j += i;
			}
		}
	}

	for(int i=1;i<Nmax;i++){
		count[i] = count[i-1] + isp[i];
	}

	int n;
	while(cin >> n){
		cout << count[n] << endl;
	}

}

C++: #include<stdio.h>

int main(void){

	int sosuu[1000000],kazu,n,i,j;

	while(scanf("%d",&n)!=EOF){

		kazu=n-1;

		for(i=2;i<=n;i++){
			sosuu[i]=1;
		}
		sosuu[0]=0;sosuu[1]=0;

		for(i=2;i<=n;i++){
			if(sosuu[i]==1){
				for(j=i*2;j<=n;j+=i){
					if(sosuu[j]==1){
						kazu--;
						sosuu[j]=0;
					}
				}
			}
		}

		printf("%d\n",kazu);
		
	}

	return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> prime;
void init(){
	for(int i=2;i<999999;i++){
		bool isprime=true;
		for(vector<int>::iterator p(prime.begin());p!=prime.end();p++){
			if(i%*p==0){
				isprime=false;
				break;
			}
		}
		if(isprime){
			prime.push_back(i);
		}
	}
}
int main(){
	int n;
	init();
	while(cin>>n){
		cout<<lower_bound(prime.begin(),prime.end(),n)-prime.begin()+1<<endl;
	}
	return 0;
}