Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

using namespace std;

const int N = 1000000;

int num[N];

void init() {
	num[0] = num[1] = 0;
	for (int i=2; i<N; ++i) num[i] = 1;
	for (int i=2; i<1000; ++i) {//素数&#31579;&#36873; 
		if (num[i * i]) {
			int j = i + i;
			for (;j < N; num[j] = 0, j += i); 
		}
	}
	for (int i=1; i<N; ++i) num[i] += num[i-1];
}

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

C++: #include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int main() {
  int n;
  
  while(!cin.eof()) {
    cin >> n;
    list<int> search_list;
    list<int> prime_number;
    while(n>=2) {
      if(n%2 != 0) 
	search_list.push_front(n);
      n--;
    }
    if(!search_list.empty())
      prime_number.push_front(2);
    while(!search_list.empty()) {
      int m = search_list.front();
      prime_number.push_back(m);
      search_list.pop_front();
      list<int>::iterator it = search_list.begin();
      while(it!=search_list.end()) {
	if((*it % m) == 0){
	  it = search_list.erase(it);
	  continue;
	}
	it++;
      }				   
    }
    cout << prime_number.size() << endl;
    prime_number.clear();
    search_list.clear();
  }
  return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << n - primes.count() - 1 << endl;
  }
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

bool pr[1000000];

template <size_t N>
void psieve(bool (&p)[N]) {
  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!p[i])
      continue;
    for (int j = i * i; j < N; j += i)
      p[j] = false;
  }
}

int solve(int n) {
  int r = 0;
  REP (i, n+1) r += pr[i];
  return r;
}

int main() {
  ios::sync_with_stdio(false);
  psieve(pr);
  int n;
  while (cin >> n) {
    cout << solve(n) << endl;
  }
  return 0;
}

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

bool isPrime(int num){
	if(num<2){
		return false;
	}
	for(int i{2};i*i<=num;++i){
		if(num%i==0){
			return false;
		}
	}
	return true;
}

int main(){
	const int MAX_NUM{1000000};
	int NUM{0};
	std::vector<bool> vPrime(MAX_NUM,false);
	for(int i{0};i<MAX_NUM;++i){
		vPrime[i]=isPrime(i);
	}

	while(std::cin >> NUM){
		int cntPrime{0};
		for(int i=0;i<=NUM;++i){
			if(vPrime[i]){
				++cntPrime;
			}
		}
		std::cout << cntPrime << std::endl;
		}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    bool p[1000000];int n,i,j;
    fill(p,p+1000000,1);p[0] = p[1] = 0;
    for(i=2;i<=999;i++){
        if(!p[i]) continue;
        for(j=i+i;j<1000000;j+=i) p[j] = 0;
    }
    while(cin >> n) cout << accumulate(p,p+n+1,0) << "\n";
}

C++: #include <iostream>
#include <vector>
using namespace std;
vector<bool> P(1000000, true);
vector<int> Q(1000000, 0);
int main()
{
	P[0] = P[1] = false;
	for (int i = 2; i * i < P.size(); ++i) {
		for (int j = 2 * i; j < P.size(); j += i)
			P[j] = false;
	}

	for (int i = 2; i < P.size(); ++i) {
		Q[i] = Q[i-1];
		if (P[i]) Q[i]++;
	}
	int n;
	while (cin >> n) cout << Q[n] << endl;
	return 0;
}

C++: #include<stdio.h>

int main(){
  const int MAX_V = 100000;
  int prime[MAX_V+1];
  int i, k, v;
  int e, f, ans;
  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(e = 0; e < 30; e++){
    int count = 0;
    scanf("%d", &v);
    for(f = 2; f <= v; f++){
      ans = prime[f];
      if(ans == 1){
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

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

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

  for(int i=2; i*i<=MAX; i++){
    if(num[i]){
      for(int j=i*2; j<MAX; j+=i){
	num[j] = false;
      }
    }
  }

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

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
using namespace std;
#define MAX 1000000
bool prime[MAX];
int main(void){ 
  prime[0] = prime[1] = false;
  long long int ans[MAX];

  fill(prime,prime+MAX,true);
  fill(ans,ans+MAX,0);
  //for(int i = 0 ; i < 10 ; i ++)cout<<ans[i]<<endl;
  //ans[2] = 1;
  for(int i = 2 ; MAX > i * i ; i ++){
    ans[i] = ans[i-1] + prime[i];
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  /*
  cout<<endl;
  for(int i = 0 ; i < 10 ; i ++)cout<<ans[i]<<endl;
  //*/
  int n;
  while(cin>>n){
    //cout<<n<<" ";
    cout<<ans[n]<<endl;
  }
 
}

C++: #include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V + 1];
int sum[MAX_V + 1];
int main() {
  int i, k, v, n, max = 0;
  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;
      }
    }
  }
  while(scanf("%d", &n) != EOF){
    for(i = 2;i <= n;i++){
      sum[n] += prime[i];
    }
  printf("%d\n", sum[n]);
  }
  return 0;
}

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

constexpr int INSUU = 64;
constexpr int SOSUU = 100000;

int Eratosthenes(int* primes){
  primes[0] = 2;
  primes[1] = 3;
  primes[2] = 5;
  primes[3] = 7;
  int prime_p = 4;
  for(int p = 11; p <= SOSUU; p+=2){
    bool is_prime = true;
    for(int i = 0; i < prime_p; i++){
      if((p % primes[i]) == 0){
	is_prime = false;
	break;
      }
    }
    if(is_prime){
      primes[prime_p++] = p;
    }
  }
  return prime_p;
}
int main(){
  int primes[SOSUU];
  int prime_count = Eratosthenes(primes);
  int n;
  while(cin >> n){
    int i = 0;
    for(; i < SOSUU; i++){
      if(n < primes[i]){
	cout << i << endl;
	break;
      }
    }
  }
}