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<iostream>
using namespace std;

static const int MAX = 1000000;

void make_prime(bool *n){
    for (int i=2; i<1000; i++) {
        if (!n[i]){
            for(int j = i*i; j < MAX; j+=i){
                n[j] = true;
            }
        }
    }
}

int main(){
    bool num[MAX] = {false};
    make_prime(num);
    int n;
    while(cin >>n){
        int ans = 0;
        for(int i=2; i<=n; i++){
            if(!num[i]){ans++;}
        }
        cout <<ans<<endl;
    }
    return 0;
}

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

using namespace std;

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

    while(cin >> n){
        prime = 0;
        for(i = n;i > 1;i--){
            count = 0;
            for(j = 2;j <= sqrt(i);j++){
                if(i % j == 0){
                    count++;
                }
            }
            if(count == 0){
                prime++;
            }
        }
        cout << prime << endl;
    }
    
    return 0;
}

C++: import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		Boorean[] bit = new Boorean[1000000];
		Arrays.fill(bit, true);
		bit[0] = false;
		bit[1] = false;

		for(int i=2; i<1000; ++i){
			if(bit[i]){
				for(int j=i*2; j<1000000; j+=i)
					bit[j] = false;
			}
		}

		int[] prime = new int[1000000];
		prime[0] = 0;
		for(int i=1; i<1000000; ++i)
			prime[i] = prime[i-1] + (bit[i] ? 1 : 0);

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String str;
		try{
			while((str = bf.readLine()) != null){
				int n = Integer.parseInt(str);
				System.out.println(prime[n]);
			}
		}
		catch(IOException ex){
			System.out.println(ex);
		}
	}
}

C++: import sys


def prime(x):
    for i in p_list:
        if x % i == 0:
            return 0
    return 1


if __name__ == "__main__":
    a = 10000
    i = 2
    p_list = []
    while i < a:
        if prime(i):
            p_list.append(i)
        i += 1
    print(p_list)

    for i in sys.stdin:
        n = int(i)
        while 1:
            if n not in p_list:
                n -= 1
            else:
                print(p_list.index(n) + 1)

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

using namespace std;
static const int MAXV = 1000000;

int sosuu_list[MAXV];

void make_sosuu_list() {
  for(int i=0;i<MAXV;i++) sosuu_list[i] = 1;
  sosuu_list[0] = sosuu_list[1] = 0;
  for(int i=2;i<MAXV;i++) {
    if(sosuu_list[i]) {
      for(int j=i+i;j<MAXV;j+=i) sosuu_list[j] = 0;
    }
  }
  for(int i=1;i<MAXV;i++)sosuu_list[i]+=sosuu_list[i-1];
}

int main() {
  int n;
  make_sosuu_list();
  while(!feof(stdin)) {
    scanf("%d", &n);
    if(feof(stdin)) break;
    printf("%d\n", sosuu_list[n-1]);
  }
}

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

using namespace std;

bool p[1000000];

void primes() {
    for (int i = 0; i < 1000000; i++) {
        p[i] = true;
    }

    p[0] = p[1] = false;

    for (int i = 2; i < sqrt(999999); i++) {
        if (p[i]) {
            for (int j = i * 2; j < 1000000; j += i) {
                p[j] = false;
            }
        }
    }
}

int main() {
    primes();

    int n;
    while (cin >> n) {
        int ans = 0;
        for (int i = 2; i <= n; i++) {
            if (p[i]) {
                ans += 1;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

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

bool isPrime(int x) {
    if (x==2) {
        return true;
    }
    if (x<2 || x%2==0) {
        return false;
    }
    for (int i=3; i*i<=x; i+=2) {
        if (x%i==0) {
            return false;
        }
    }
    return true;
}
int main() {
    int n;
    int cnt;
    while (scanf("%d",&n)!=EOF) {
        cnt=0;
        for (int i=0; i<=n; i++) {
            if (isPrime(i)) {
                cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}

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

const int MAX_N=1000000;
int prime[MAX_N+1];
bool isPrime[MAX_N+1];

int main(int N){
	int count=0;
	while(cin>>N){
		for(int i=0;i<=N;i++)
		isPrime[i]=true;
	isPrime[0]=isPrime[1]=false;
	for(int i=2;i<=N;i++){
		if(isPrime[i]){
			prime[count++]=i;
			for(int j=2*i;j<=N;j+=i)
				isPrime[j]=false;
		}
	}
	return count;
	cout<<count<<endl;
}
	
	}

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

int main()
{
 bool prime[1000000];
 for(int i=0; i<1000000; i++) prime[i] = true;

 prime[0] = prime[1] = false;
 for(int i=0; i<1000000; i++)
  if(prime[i]){
   for(int j=i; j<1000000; j += i)
    prime[j] = false;
  }

 int n;
 while(cin >> n){
  int c = 0;
  for(int i=0; i<=n; i++)
   if(prime[i]) c++;
  
  cout << c << '\n';
 }

 return 0;
}

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

using namespace std;
const int max_d = 30;

int sieve(int n) {
    int res = 0;
    bool prime[n + 1];
    for(int i = 0; i <= n; i++) {
        prime[i] = true;
    }
    for(int i = 2; i <= n ; i++) {
        if(prime[i]) {
            res++;
            for(int j = 2 * i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    return res;
}

int main() {
    int n;
    int dc = 0;
    while(cin >> n) {
        dc++;
        if(dc > max_d) break;
        cout << sieve(n) << endl;
    }
    return 0;
}

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

using namespace std;

#define MAX_N 10000000

int sosuu[MAX_N+1];

int main() {
	for (int i = 0; i < MAX_N; ++i)
		sosuu[i] = 1;

	sosuu[0] = sosuu[1] = 0;

	for (int i = 2; i < MAX_N; ++i)
		if (sosuu[i])
			for (int j = 2*i; j < MAX_N; j += i)
				sosuu[j] = 0;

	for (int i = 0; i < MAX_N; ++i)
		sosuu[i+1] += sosuu[i];

	int n;
	while ( scanf("%d", &n) != EOF )
		cout << sosuu[n] << endl;
}

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

int main(){
	int i=0,k=2,source[30];
	while(cin >> source[i]) i++;
	int m = max(source[0],source[i]);
	bool hurui[1000000];
	memset(hurui+2,1,sizeof(hurui));
	for (int j=2;j<=m;j++,k=2)
	{
		if (!hurui[j]) continue;
		while(j*k < m)hurui[j*k]=false,k++;
	}
	for (int j=0;j<i;j++){
		int count=0;
		for (k=2;k<=source[j];k++) count += !!hurui[k];
		cout << count << endl;
	}
}

C++: #include <iostream>
#include <math.h>
#define MAX 1000
using namespace std;

int main(){
	int n;
	int prime[MAX],i,j;
	int count;
	bool flag;

	while((cin >> n)!= NULL){
		count = 0;
		for(i = 3; i <= n; i+=2){
			flag = true;
			for(j = 0; j < count; j++){
				if(i % prime[j] == 0){
					flag = false;
					break;
				}
			}
			if(flag == true){
				prime[count++] = i;
			}
		}
		if(n > 1)	count++; //2
		cout << count << endl;
		//delete[] prime;
	}
	return 0;
}