Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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

using namespace std;
int main() {
  long n;
  vector<long> primes;
  primes.push_back(2);
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 3; i <= n; i += 2) {
      bool prime = true;
      for (unsigned int j = 0; j < primes.size() && primes[j] * primes[j] <= n; j++)
        if (i % primes[j] == 0) {
          prime = false;
          break;
        }
      if(prime) primes.push_back(i);
    }
    int x = 0;
    for (long& e: primes)
      if (e <= n) x++;
    cout << x << endl;
  }
}

C++: #include <stdio.h>

int main(){

	int a[99999] = {2,3,5},i,n,m=0,b=3,c=0;
	while (scanf("%d",&n)!=EOF){
		for (i = 2; i < n+1; i++){
			if (i % a[m] == 0){
				a[b] = i, b++, c++;
				}
		}printf("%d\n", c);
		}
	return 0;
}

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

#define add push_back
#define inf 2147000000

#define rep(i,n) for(int i=0;i<n;i++)
#define out(a) cout<<a<<endl;

using namespace std;

int main(void){
	int sosuu[50000];
	int cont=0;
	int n;
	scanf("%d",&n);
	
	for(int i=2;i<=n;i++){
		for(int j=0;;j++){
			if(j==cont){
				sosuu[cont]=i;
				cont++;
				break;
			}
			if(i%sosuu[j]==0){
				break;
			}
		}
	}
	out(cont);
}

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

int main()
{
	int n[30];
	int i = 0;
	while(cin >> n[i]) {i++;}
		
	for (int k = 0;k < i;k++){
		int s = 0;
		for (int j=3;j<=n[k];j++){
			int y = 0;
			for (int m=1;m<=j;m++){
				if (j%m == 0){y++;}
			}
			if (y == 2){s++;}
		}
		cout << s << endl;
	}	
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vi;

int n;
vi eratosthenes_sieve(int n){
	vi res(n+1);
	if(n<2) return res;
	res[2]=1;
	for(int i=3;i<=n;i+=2){
		if(i*i<=n && !res[i]) for(int j=i+i+i;j<=n;j+=i+i) res[j]=1;
		res[i]=!res[i];
	}
	return res;
}
vi prime_list(const vi& isprime){
	vi res;if(isprime.size()<=2)return res;
	res.push_back(2);
	for(unsigned int i=3;i<isprime.size();i+=2)
		if(isprime[i])res.push_back(i);
	return res;
}
vi prime_list(int n){
	return prime_list(eratosthenes_sieve(n));
}

main(){
	vi pl = prime_list(1000000);
	while(cin >> n) cout << (upper_bound(pl.begin(), pl.end(), n) - pl.begin()) << endl;
	return 0;
}

C++: #coding: UTF-8

from bisect import bisect_right

max_number = 1000000
prime_flag_list = [True] * max_number

prime_flag_list[0] = False
prime_flag_list[1] = False

prime_flag_list[4::2] = [False] * len(prime_flag_list[4::2])

for i in range(3, int(max_number**0.5) + 1, 2):
    prime_flag_list[i*i::i] = [False] * len(prime_flag_list[i*i::i])

prime_list = [i for i in range(2, max_number) if prime_flag_list[i]]

while True:
    try:
        input = int(raw_input())
    except EOFError:
        break

    print bisect_right(prime_list, input)

C++: #include <cstdio>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#define min(a,b)    (((a) < (b)) ? (a) : (b))
#define max(a,b)    (((a) > (b)) ? (a) : (b))
#define abs(x)    ((x) < 0 ? -(x) : (x))
#define INF 0x3f3f3f3f
#define delta 0.85
#define eps 1e-3
#define PI 3.14159265358979323846
#define MAX_N 1000005
using namespace std;
int cnt[MAX_N];
bool is_prime[MAX_N];

void sieve(int n){
	int limit = sqrt(n);
	for(int i = 0; i <= n; i++) is_prime[i] = 1;
	is_prime[0] = is_prime[1] = 0;
	cnt[0] = cnt[1] = 0;
	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			cnt[i] = cnt[i - 1] + 1;
			if(i <= limit){
				for(int j = i * i; j <= n; j += i) is_prime[j] = 0;
			}
		}
		else cnt[i] = cnt[i - 1];
	}
}

int main(){
	int n;
	sieve(MAX_N);
	while(~scanf("%d", &n)){
		printf("%d\n", cnt[n]);
	}
	return 0;
}

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

int main()
{
    int i,j,flag,n,c=0;
    scanf("%d",&n);
    for(i=2;i<=n;i++)
    {
        flag=0;
        for(j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            c++;
        }
    }
    printf("%d",c);
    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 <bits/stdc++.h>

const static double	de_PI	= 3.14159265358979323846;
const static int	de_MOD	= 1000000007;
const static int	de_MAX	= 999999999;
const static int	de_MIN = -999999999;

bool Judge_PrimeNumber(const int a) {

	if (a < 2) { return false; }
	if (a == 2) { return true; }
	if (a % 2 == 0) { return false; }

	for (int i = 3; i <= a / i; i += 2) {
		if (a%i == 0) {
			return false;
		}
	}
	return true;
}

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());

	int n = 0, ans = 0;
	std::vector<int> A;

	while (std::cin >> n) {
		A.push_back(n);
	}

	for (unsigned int i = 0; i < A.size(); i++) {

		if (n == 1) {
			std::cout << 0 << std::endl;
			continue;
		}
		ans = 1;
		for (int j = 3; j <= A[i]; j += 2) {
			if (Judge_PrimeNumber(j)) {
				ans++;
			}
		}
		std::cout << ans << std::endl;
	}

}

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

unsigned isPrime(unsigned x) {
	static std::vector<unsigned> primes{2};
	if (x < 2) {
		return 0;
	}
	if (x == 2) {
		return 1;
	}
	if (primes.back() < x) {
		for (unsigned i = primes.back() + 1; i*i <= x; i++) {
			bool isPrime = std::none_of(primes.begin(), primes.end(), [i](auto d){ return i % d == 0; });
			if (isPrime) {
				primes.push_back(i);
			}
		}
	}
	bool isPrime{true};
	for (auto&& var : primes) {
		if (var >= x) break;
		if (x % var == 0) {
			isPrime = false;
			break;
		}
	}
	return (isPrime) ? 1 : 0;
}

unsigned numOfPrime(const unsigned& x) {
	unsigned sum{};
	static unsigned ntable[999999]{};
	static unsigned maxX{1};
	if (x < 2) {
		return 0;
	}
	if (x == 2) {
		return 1;
	}
	unsigned count_from = std::min(maxX, x);
	sum += ntable[count_from];
	for (unsigned i = count_from + 1; i <= x; i++) {
		sum += isPrime(i);
		ntable[i] = sum;
	}
	maxX = std::max(x,maxX);
	return sum;
}

int main(int argc, char const* argv[])
{
	unsigned d{};
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while (std::cin >> d) {
		std::cout << numOfPrime(d) << std::endl;
	}
	return 0;
}