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<stdio.h>
using namespace std;

bool p[1000010];
int input;

void erato(){
	fill(p, p+1000010, true);
	p[0] = p[1] = false;

	for(int i=0; i * i < 1000010; i++){
		if(!p[i]) continue;

		for(int j = i + i; j < 1000010; j += i){
			p[j] = false;
		}
	}
}

int main(){
	erato();
	int input;

	while(scanf("%d", &input) != EOF){
		int ans = 0;
		for(int i=0; i <= input; i++){
			if(p[i]) ans++;
		}
		cout << ans << endl;
	}
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009

#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> prime;

void Prime() {
	prime.emplace_back(2);
	for (int i = 3; i <= 999999; i += 2) {
		bool f = false;
		for (int j = 3; j <= sqrt(i); j += 2) {
			if (i%j == 0) {
				f = true;
				break;
			}
		}
		if (!f) prime.emplace_back(i);
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	Prime();
	int n;
	while (cin >> n) {
		cout << upper_bound(prime.begin(), prime.end(), n) - prime.begin() << endl;
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,k,sum,check;
    int t=1;
    vector<int> prime;
    prime.push_back(0);
    prime.push_back(0);
    for(int i=2;i<1000000;i++){
        prime.push_back(1);
    }
    while(t<1000000){
        for(int j=t+1;j<=1000000;j++){
            if(prime[j]==1){
                t=j;
                for(k=2*j;k<=1000000;k+=j){
                    prime[k]=0;
                }
                break;
            }
            else if(j==1000000){
                t=1000000;
            }
        }
    }
    while(cin>>n){
        sum=0;
        for(check=1;check<=n;check++){
            if(prime[check]==1){
                sum+=1;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(void){
	
	long int n,f,k,i;
	int count;
	bool chk;
	while(cin>>n){
		count=0;
		for(i=2;i<=n;i++){
		
			chk=0;
			f=i/2;
			k=2;
		
			while(f>=k){
				if((i%k)==0){
					chk=true;
					break;
				}
				k++;
			}
		
			if(chk==false){
				count++;
			}
		}
		cout<<count<<endl;
	}
}

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=1;
	
		for (int j=3;j<=n[k];j++){
				//judgement of prime number
				for(int m=2;m<j;m++){
					if(j%m==0){break;}
					if(m==j-1){s=s+1;}
				}
		}
	cout << s <<endl;
	}
	
    return 0;
}

C++: // BCC
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

// GCC
// #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define each(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int INF = 1 << 28;
const ll INFLL = 1ll << 56;


/**
 * ??¨????????????????????????
 * ?´???°??¨??¨?´???°?????????????????????
 */

const int SIEVE_SIZE = 2000000;

bool is_prime[SIEVE_SIZE];
vector<int> primes;

void eratosthenes()
{
	primes.clear();
	for (int i = 2; i < SIEVE_SIZE; i++) is_prime[i] = true;
	
	for (int i = 2; i * i < SIEVE_SIZE; i++){
		if (!is_prime[i]) continue;
		primes.pb(i);
		for (int j = i * i; j < SIEVE_SIZE; j += i){
			is_prime[j] = false;
		}
	}
}

int sum[1000000];

int main()
{
	eratosthenes();
	each(p, primes) sum[*p]++;
	rep(i, 999999) sum[i + 1] += sum[i];
	
	int n;
	while (~scanf("%d", &n)){
		printf("%d\n", sum[n]);
	}
}

C++: #include<stdio.h>
#define N 1000000

int main() {
	int ipt;
	int root;
	int cnt = 0;
	int A[N];
	for (int i = 1; i <= N; i++) {
		A[i] = i;
	}
	for (int pos = 2; pos*pos <= N; pos++) {
		root = A[pos];
		if (!root)continue;
		for (int k = 2; k*root <= N; k++) {
			A[k*root] = 0;
		}
	}

	while(scanf("%d",&ipt)==1) {
		for (int i = 2; i <= ipt; i++) {
			if (A[i] != 0)cnt++;
		}
		printf("%d\n", cnt);
		cnt = 0;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

const int kSieveSize = 1000001;
bool sieve[kSieveSize] = {true, true};

int main()
{
  vector<int> primes;
  primes.reserve(kSieveSize);
  for (int i = 2; i * i < kSieveSize; ++i){
    if (sieve[i]) continue;
    primes.push_back(i);
    for (int j = i * i; j < kSieveSize; j += i){
      sieve[j] = true;
    }
  }
  for (int n; ~scanf("%d", &n); ){
    printf("%d\n", upper_bound(primes.begin(), primes.end(), n) - primes.begin());
  }

  return (0);
}

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

using namespace std;

int main() {

	int n;
	int i,j;

	while (cin >> n) {
		int counter = 1;

		for (i = 3; i <= n; i = i + 2) {
			int kari = 1;
			for (j = 3; j < i; j=j+2) {
				if ((j % 3 == 0 && j != 3) || (j % 5 == 0 && j != 5) || (j % 7 == 0 && j != 7) || (j % 11 == 0 && j != 11) || (j % 13 == 0 && j != 13) || (j % 17 == 0 && j != 17) ||
					(j % 19 == 0 && j != 19) || (j % 23 == 0 && j != 23)) {
					continue;
				} else if (i % j == 0) {
					kari = 0;
					break;
				}
			}

			if (kari != 0) {
				counter++;
			}
		}

		cout << counter << endl;
	}

	return 0;
}

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

vector<int> Prime;
void PrimeCalc() {
  bool IsPrime[1000000];
  for(int i=0; i<1000000; i++) {
    IsPrime[i] = true;
  }
  IsPrime[0] = IsPrime[1] = false;
  for (int i=2; i<1000000; i++) {
    if (IsPrime[i]) {
      Prime.push_back(i);
      for (int j=2*i; j<1000000; j+=i) {
        IsPrime[j] = false;
      }
    }
  }
}

void solve() {
  PrimeCalc();
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i=0; i<Prime.size(); i++) {
      if (Prime[i]<=n) {
        ans++;
      } else {
        break;
      }
    }
    cout << ans << endl;
  }
}

int main() {
  solve();
  return 0;
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int list[100000];

    cnt=0;
    for (long i=2; i<1000000; i++){
	//    printf("%d %d\n",i, cnt);
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
	printf("input : ");
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (long i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;

    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include <stdio.h>

int sieve(int n)
{
	char prime[999999];
	int i, j;
	int p;
	
	for (i = 0; i <= n + 1; i++){
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;
	
	for (i = 2; i <= n + 1; i++){
		if (prime[i]){
			for (j = 2 * i; j <= n; j += i){
				prime[j] = 0;
			}
		}
	}
	for (i = 0, p = 0;i <= n; i++){
		if (prime[i] == 1){
			p++;
		}
	}
	
	return (p);
}

int main(void)
{
	int num;
	int ans;
	
	while (scanf("%d", &num) != EOF){
		ans = sieve(num);
		
		printf("%d\n", ans);
	}
	
	return (0);
}