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>
int main(){
	int n;
	while(std::cin>>n){
		int ans=0;
		std::vector<int> vec(n);
		for(int i=0;i<n;i++)vec[i]=1;
		vec[0]=vec[1]=0;
		for(int i=2;i<n;i++){
			if(vec[i] == 1){
				ans++;
				for(int j = 2 * i ; j < n ; j += i){
					vec[j]=0;
				}
			}
		}
		if(n==2)std::cout<<1<<std::endl;
		else std::cout<<ans<<std::endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
    long long n,count=0;
    cin >> n;
    for(long long i=2;i<n;i++){
        long long f;
        for(f=2;f<i;f++){
            if(i%f==0){
                break;
            }
        }
        if(i==f)
            count++;;
    }
    printf("%I64d\n",count);
    return 0;
}

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

int main()
{
	int n, x = 0;
	int countdata[1000];
	while (cin >> n) {
		int count = 0;
		for (int a = 2; a <= n; a++) {
			if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a % 7 != 0) {
				count++;
			}
		}
		countdata[x] = count;
		x++;
	}
	for (int a = 0; a < n; a++) {
		cout << countdata[a] << endl;
	}
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>

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;
      }
    }
  }
  for(;temp < n; temp++){
    num_A[temp] = N;
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
const int MAX_V = 1000000; // 100????????§?´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????? 
int pcount[MAX_V+1];
int main() {
    int i, k,a,sum=0;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1; // 2??\????´???°??¨??????
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°2?????\????????°?´???°??§?????? 
            }
            
        } 
        
    }
    pcount[0]=0;
    pcount[1]=0;
    for(i=2;i<MAX_V;i++){
        if(prime[i]){
            sum++;
        }
        pcount[i]=sum;
    }
    for(i=0;i<30;i++){
        scanf("%d",&a);
        printf("%d\n",pcount[a]);
    } 

    return 0; 
    
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;


vector<int> p;
int main(void){
    p.pb(2);
    for(int i = 3; i <1000000; i += 2){
        int j;
        for(j = 0; p[j] * p[j] <= i; ++j){
            if(i % p[j] == 0) break;
        }
        if(i % p[j] > 0) p.pb(i);
    }
    int n;
    while(cin >> n){
        if(n == 1){
            cout << 0 << endl;
            continue;
        }
        int l = 0, r = p.size();
        while(l + 1 != r){
            int t = (l + r)/2;
            if(p[t] <= n) l = t;
            else r = t;
        }
        int ret;
        if(n < p[r]) ret = r;
        else ret = l;
        cout << ret << endl;
    }
    return 0;
}

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

int main() {
  int N = 1000000;
  vector<int> table(N, 1);
  table[0] = table[1] = 0;
  for (int i = 2; i * i < N; i++)
    if (table[i])
      for (int j = i * 2; j < N; j += i)
        table[j] = 0;

  int x;
  while(cin >> x) {
    int ans = 0;
    for (int i = 2; i <= x; i++) {
      if (table[i])
        ans++;
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <math.h>
#define MAX 1000010
using namespace std;

int main(){
	int n;
	int *prime,i,j;
	prime = new int[80000];
	int *answer = new int[MAX];
	int count;
	bool flag;

	count = 1;
	answer[0] = 0;
	answer[1] = 0;
	answer[2] = 1;
	for(i = 3; i <= 1000000; i+=2){
		flag = true;
		for(j = 0; j < count; j++){
			if(i % prime[j] == 0){
				flag = false;
				break;
			}
			if(prime[j] * prime[j] > i) break;
		}
		if(flag == true){
			prime[count++] = i;
		}
		answer[i] = count;
		answer[i+1] = count;
	}
	while((cin >> n)!= NULL){
		cout << answer[n] << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
#define inf 0x3f3f3f3f
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int prime[1000010];
bool IsPrime[1000010];


void init() {
	memset(prime,inf,sizeof(prime));
	memset(IsPrime,true,sizeof(IsPrime));
	int num=0;
	for(int i=2; i<999999; i++) {
		if(IsPrime[i]) {
			prime[num++]=i;
			if(i<=sqrt(999999)) {
				for(int j=i*i; j<999999; j=j+i) {
					IsPrime[j]=false;
				}
			}
		}
	}
}
int main() {

	int x;
	init();
	while(scanf("%d",&x)!=EOF) {
		printf("%d\n",upper_bound(prime,prime+999999,x)-prime);
	}

	return 0;
}

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

using namespace std;

vector<int> PrimeNumber;
int p = 0;

int f(int x){
	if (x == 2) {
		PrimeNumber.push_back(x);
		return 1;
	}
	for (int i = 0; i < PrimeNumber.size(); i++){
		if (x%PrimeNumber[i] == 0) return 0;
	}
	PrimeNumber.push_back(x);
	return 1;
}

int main(){
	long int n;
	int ans = 0;
	while (1){
		cin >> n;
		ans = 0;
		PrimeNumber.clear();
		for (int i = 2; i <= n; i++){
			ans += f(i);
		}
		cout << ans << endl;
	}
}

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

int main() {
  bool check_prime[1000000] = {false};
  int n;

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

  while (cin >> n) {
    int answer = 0;
    for (int i = 2; i <= n; i++) {
      if (!check_prime[i]) { 
        answer++;
      }
    }
    cout << answer << endl;
  }

  return 0;
}