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 <cmath>

using namespace std;


int main(){
	const int MAX_NUM=1000000;
	int table[MAX_NUM]={};
	for(int i=2;i<1001;i++){
		if(table[i]==1)continue;
		for(int j=i*2;j<MAX_NUM;j+=i){
			table[j]=1;
		}
	}

	int input;
	while(cin>>input){
		int count=0;
		for(int i=2;i<input;i++){
			//cout<<"table:"<<i<<"="<<table[i]<<"\n";		
			if(table[i]==0)count++;
		}
		cout<<count<<"\n";
	}
	return 0;
}

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

int main(){
int n;
cin >> n;
int a[n+1];
int b;
int c;
b=1;
while(b<n+1){
a[b]=0;
b=b+1;}
a[1]=1;
b=2;
while(b<n+1){
if(a[b]=0){ c=2; while(1){if(c*b>n){break;} a[c*b]=1; c=c+1;}
b=b+1;}

int d;
d=0;
b=1;
while(b<n+1){
if(a[b]=0){d=d+1;}
b=b+1;}
cout << d;


}

C++: #include <stdio.h>

#define MAX_V 1000001
int prime [MAX_V];

int main()
{
	int i, k, n, a=0, b=0;
	int cnt[MAX_V];

	for(i=2; i<MAX_V; i++)
	{
		prime[i] = 1;
	}

	for(i=2; i*i<=MAX_V; i++)
	{
		if(prime[i])
		{
			for(k=2*i; k<MAX_V; k+=i)
			{
				prime[k] = 0;
			}
		}
	}

	for(i=2; i<MAX_V; i++)
	{
		if(prime[i])
		{
			b++;
		}
		cnt[i] = b;
	}

	while(scanf("%d",&n)!= EOF)
	{
		printf("%d\n",cnt[n]);
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

#define NMAX 1000001
bool p[NMAX];
int c, cnt[NMAX];
void show(){
  for(int i = 0; i < 20; i++){
    cout << "@" << i << ":" << p[i] << endl;
  }
}
void prime(){
  fill(p, p+NMAX, true);
  p[0] = p[1] = false;
  for(int i = 4; i < NMAX; i+=2)p[i] = false;
  for(int i = 3; i*i < NMAX; i+=2){
    if(p[i]){
      for(int j = i+i; j < NMAX; j+=i){
	p[j] = false;
      }
    }
  }
  for(int i = 0; i < NMAX; i++){
    if(p[i])c++;
    cnt[i] = c;
  }
}
int main(){
  prime();
  int n;
  while(cin >> n){
    cout << cnt[n] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;


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;
    }

    int N;
    while(cin >> N){
        cout << prime[N] << '\n';
    }
    return 0;
}

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

int main(){
	int n;
	vector<int> prime;
	bool num[1000001];
	for(int i = 0; i < 1000001; i++){
		num[i] = true;
	}
	num[0] = false;
	num[1] = false;

	for(int i = 2; i <= 1000; i++){
		for(int j = i*2; j <= 1000000; j += i){
			if(!num[j]){
				continue;
			}
			num[j] = false;
		}
	}

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

	return(0);
}

C++: #define _USE_MATH_DEFINES
#define llint long long
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int pn = 0;
int p[1000000];
void getsosu(int Max) {
    for(int i = 2; i <= Max; i++) {
        bool flg = true;
        for(int j = 0; j < pn; j++) {
            if(p[j] * p[j] > i) break;
            if(i % p[j] == 0) {
                flg = false;
                break;
            }
        }
        if(flg) p[pn++] = i;
    }
}

int main() {
    getsosu(999999);

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

C++: #include <iostream>
#include <vector>
using namespace std;
int main()
{
    vector<int> primes;
    primes.push_back(2);
    int Testcase,Counter;
    while(cin >> Testcase)
    {

        Counter = 0;
        if(Testcase >= 2)
        {
            Counter++;
        }
        for(int i=3; i <= Testcase; i+=2)
        {
            bool prime=true;
            for(int j=0;j<primes.size() && primes[j]*primes[j] <= i;j++)
            {
                if(i % primes[j] == 0)
                {
                    prime=false;
                    break;
                }
            }
            if(prime)
            {
                primes.push_back(i);
                Counter++;
            }

        }
        cout << Counter << endl;
    }

}

C++: #include <iostream>

using namespace std;

int w=0;
int HEY(int i){

	w=0;
	while(1){
		if(w*w>i){break;}
		w++;
	};
	return w;
}


int main(){
	int n=0,m=0,o=0,f=0,c=0;

	while(cin>>n){
		c=0;

	for(o=2;o<=n;o++)
	{	f=0;
		for(m=2;m<HEY(o);m++){
			if(o%m == 0){f++;}

		};
		if(f==0){c++;};

	};
	cout<<c<<endl;
	};
 return 0;

}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int *p=upper_bound(prime,prime+num,n);
        int ans=p-prime;
        cout<<ans<<endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}