Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

C++:  /*
Write a program which reads an integer n (n &#8804; 999999) and prints the number of prime numbers which are less than or equal to n. A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5, 7.
 */

#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

 /* 
http://community.appliplanet.co.jp/community/beginner

[|Cg]
+nªfÅÈ¢ÈçÌ½ûªmæè¬³¢àÌÅèØêéÍ¸B
+\ßQÌ{ðO·éB
+ªå«­ÈéÈçÎGXgeXÌâ¿ðÂ©¤©ÀÍbool[]ðg¤B
 */
void solve(int n) {
	bool prime[n+1];
	for (int i=0; i<n+1; i++)
		prime[i] = true;
	prime[0] = false; prime[1] = false;
	int m = (int)sqrt(n);					// nÌ½ûª
	
	for (int i=2; i<=m; i++) {
		if(prime[i]) {
			for (int k=i*i; k<=n; k += i)
				prime[k] = false;
		}
	}
	
	int count = 0;
	for (int i=0; i<n+1; i++) {
		if (prime[i]) count++;
	}
	
	cout << count << endl;
}

int main() {
	int n;
	while (cin >> n) {
		solve(n);
	}
	return 0;
}