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>
using namespace std;
bool b[1000005];
int s[1000005];
int main(){
	int i,j,k;
	int n;
	b[i]=true;
	for(i=2;i<1000000;i++){
		if(b[i]==false){
			for(j=2*i;j<1000000;j+=i){
				b[j]=true;
			}
			s[i]=s[i-1]+1;
		}else{
			s[i]=s[i-1];
		}
	}
	while(cin>>n){
		cout<<s[n]<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	bool a[1000000] = {1,1};
	int n, i, j, f = 0, count = 0;
	while (cin >> n) {
		count = 0;
		while (f <= ceil(sqrt(n))) {
			i = f + 1;
			while (a[i] == 1) {
				i++;
			}
			f = i;
			for (j = i + 1; j <= n; j++) {
				if (j % f == 0) a[j] = 1;
			}
		}
		for (i = 0; i <= n; i++) {
			if (a[i] == 0) { count++;}
		}
		cout << count << endl;
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
long long ll;

const int N = 1000000;
bool prime[N];
int cnt[N];

bool isPrime(int n) {
	int i;
	for (i=2; i<n; i++)
		if (n%i == 0) return false;
	return n != 1;
}

void setPrime(int n) {
	int i, j;
	prime[0] = prime[1] = false;
	for (i=2; i<=n; i++) prime[i] = true;

	for (i=2; i<=n; i++) {
//		if (isPrime(i)) prime[i] = true;
		if (prime[i])
			for (j=i*2; j<=n; j+=i) prime[j] = false;
	}
}

int main() {
	int i, j;
	int n;

	setPrime(N);

	for (i=2; i<N; i++) {
		cnt[i] = cnt[i-1];
		if (prime[i]) cnt[i]++;
	}

	while (scanf("%d ", &n) != EOF) {
		printf("%d\n", cnt[n]);
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int d[1000000]={},p[1000000]={};
void calc(){
    for(int i=2;i<1000000;i++){
        if(d[i]==0){
            for(int j=2;j<1000000;j++){
                if(i*j>1000000) break;
                    d[i*j]=1;
            }
        }
    }
    for(int i=2;i<1000000;i++){
        if(d[i]==0)
        p[i]=p[i-1]+1;
        else
        p[i]=p[i-1];
    }
}
int main(){
    calc();
    int n;
    while(cin>>n,n){
        if(cin.eof())break;
        cout<<p[n]<<endl;
    }
    return 0;
}

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

using namespace std;

#define NUM_LIMIT 1000000   // numbers < NUM_LIMIT

int getNumOfPrimes(bitset<NUM_LIMIT> &isPrime, int min, int max){
    int cnt = 0;
    for (int i = 2; i <= max; i++){
        if (!isPrime[i]) continue;  // skip non prime numbers
        cnt ++;
        if (i >= min){
            // cross out the multiples of the number
            for (int j = 2; i*j <= max; j++){
                isPrime[i*j] = 0;
            }
        }
    }
    return cnt;
}

int main(){
    //ifstream cin("input.txt");
    bitset<NUM_LIMIT> isPrime;
    isPrime.set();  // set all bits to 1
    
    // input data
    int number;
    int max_num = 0;
    while(cin >> number){
        int cnt = 0;
        if (number > max_num){
            cnt = getNumOfPrimes(isPrime, max_num+1, number);
            max_num = number;
        } else {
            cnt = getNumOfPrimes(isPrime, number+1, number);
        }
        cout << cnt << endl;
    }
    return 0;
}

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

#define N 999999+1
int prime[N];
void sieve(int en) {
  // prime[prime number] = 0
  // prime[not prime number] = 1
  for(int i=2;i<=(int)sqrt(en);i++) {
    for(int j=i*2;j<=en;j+=i) {
      prime[j] = 1;
    }
  }
}

int main() {
  int n;
  int max_n = 2;
  while(cin >> n) {
    if(n > max_n) {
      sieve(n);
    }
    int cnt = 0;
    for(int i=2;i<=n;i++) {
      if(prime[i] == 0)
        cnt++;
    }
    cout << cnt << endl;
  }
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		for(int i = 2; i <= n; i++){
			if(a[i]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int data[999999] = { -1 };
bool notprime[999999] = { false };

int main(int argc, char **argv){
	int n;
	int cnt;
	while (cin >> n) {
		cnt = 0;
		for (int i = 2; i < n; i++) {
			if (!notprime[i]) {
				cnt++;
				for (int j = 2; j <= n / i; j++) {
					notprime[i * j] = true;
				}
			}
			if (i >= sqrt(n)) {
				for (int k = i + 1; k <= n; k++) {
					if (!notprime[k]) {
						cnt++;
					}
				}
				break;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
	int n;
	
	while(scanf("%d",&n)==1){
	int count=0;
	double sqrtn = n;
		for(int i=3;i<=n;i+=2){
			bool p=true;
			for(int j=3;j<sqrt(sqrtn);j++){
				if(i % j == 0){
					p=false;
					break;
				}
			}
			if(p) count++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}

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

using namespace std;

#define MAX 1000100
#define LIM 1010

bool composite[MAX + 100];
int prime[MAX + 100];

void sieve()
{
    for(int i = 2; i <= LIM; i++){
        for(int j = i * i; j <= MAX; j += i)
            composite[j] = true;
    }
    int counter = 0;
    for(int i = 2; i <= MAX; i++){
        if(!composite[i]) counter += 1;
        prime[i] = counter;
    }
}

int main()
{
    sieve();
    int n;
    while(cin >> n){
        cout << prime[n] << "\n";
    }
}

C++: /// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009
/// http://www.tsg.ne.jp/TT/tsg/c/mansaku/P01.html
#include<cstdio>
#include<cmath>

int main(){
    int n, cnt=0;
    scanf("%d", &n);
    for(int i = 3; i<=n; i+=2){
        int k= 0;
        for(int j=3; j<sqrt(i); j+=2){
            if(i%j==0){
                k=1;
                break;
            }
        }
        if(k==0) cnt++;
    }
    printf("%d\n", cnt);

    return 0;
}

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

bool isprime(int x){
	if(x==2) return true;
	if(x<2 && !(x%2)) return false;
	x = int(ceil(sqrt(x)));
	for(int i=3;i<=x;i+=2){
		if(!(x%i)) return false;
	}
	return true;
}

int main(){
	int x,i,cnt;
	while(cin>>x){
		cnt=0;
		for(i=2;i<=x;i++){
			if(isprime(i)) cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}