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

bool x[1000000];

void pri(int num){
	for(int i = 0; i <= num; i++) cout <<"x["<<i<<"] = "<<x[i]<<endl;
}

void setbool(int num){
	x[0] = false; x[1] = false;
	for(int i = 2; i <= 1000000; i++) x[i] = true;
	for(int i = (num + 1); i <= 1000000; i++) x[i] = false;
}

void loop(int num){
	for(int i = 2; i <= num; i++){
		if(x[i] == false) continue;
		else{
			int j = i;
			while(j < num){
				j++;
				if(x[j] == true && j % i == 0) x[j] = false;
			}
		}
	}
}

int ans(){
	int cou = 0;
	for(int i = 0; i <= 1000000; i++) if(x[i] == true) cou++;
	return cou;
}

int main(){
	int num, cou = 0, i;
	
	while(cin >>num){
		setbool(num);
		loop(num);
		cout <<ans()<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int a[10000];
    int n;
    a[0]=2;
    int k=1;
while(cin>>n){
    for(int i=3;i<=n;i++){
        for(int j=0;j<=k;j++){
            if(j==k){
                a[k]=i;
                k++;
                break;
             }
            if(i%a[j]==0)break;
        }
    }
    cout<<k<<endl;
    k=1;
 }
}

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

using namespace std;

const int MAX_N = 1000000;

int prime[MAX_N];
bool is_prime[MAX_N];

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

int main()
{
	int n;
	while(scanf("%d",&n) > 0){
		printf("%d\n",sieve(n));
	}
}

C++: /*
Á·Ï°Ìâ£ºPrime Number_AOJ 0009 
*/

#include <bits/stdc++.h>
using namespace std;

const int MAX_N=1000007;

//°£ÊÏÉ¸·¨(Sieve of Eratosthenes)
int prime[MAX_N]; //µÚi¸öËØÊý£¬´ËÎª´æ·ÅËØÊýµÄÊý×é 
bool is_prime[MAX_N]; //is_prime[]ÎªtrueÊ±ÎªËØÊý

//·µ»ØnÒÔÄÚËØÊýµÄ¸öÊý
int sieveErato(int n)
{
	int p=0;
	for(int i=0; i<=n; i++)
		is_prime[i]=true;
	is_prime[0]=false;
	is_prime[1]=false;
	for(int i=2; i<=n; i++)
	{
		if(is_prime[i])
		{
			prime[p++]=i;
			for(int j=2*i; j<=n; j+=i)
				is_prime[j]=false;
		}
	}
	return p;
}


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

C++: #include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int isPrime[1000000];


void era(){
    for(int i=2;i<1000000;i++){
        if( isPrime[i]==1 ){
            int k = 2;
            while(k*i<1000000){
                isPrime[k*i]=0;
                k++;
            }
        }
    }
}


int main(){
    for(int i=0;i<1000000;i++){
        isPrime[i]=1;
    }
    isPrime[0]=isPrime[1]=0;
    
    era();
    
    int n;
    while(cin>>n){
        int count=0;
        for(int i=0;i<=n;i++){
            if( isPrime[i] )count++;
        }
        cout<<count<<endl;
    }
    
    
    
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long long int i;
	int n, p, cnt,fg;
	while (cin >> n) {
		i = 3;
		cnt = 1;
		fg = 0;	
		
		if ((int)log10(n) == 3) {
			cnt = 168;
			i = 1001;
		}
		else if ((int)log10(n) == 4) {
			cnt = 1229;
			i = 10001;
		}
		else if ((int)log10(n) == 5) {
			cnt = 9592;
			i = 100001;
		}
		if (110000<n) {
			cnt = 10453;
			i = 110001;
		}
		if (120000 < n) {
			cnt = 11301;
			i = 120001;
		}
		if (130000 < n) {
			cnt = 12159;
			i = 130001;
		}
		if (140000<n) {
			cnt = 13010;
			i = 140001;
		}
		if (150000<n) {
			cnt = 13848;
			i = 150001;
		}
		if (160000<n) {
			cnt = 14683;
			i = 160001;
		}
		if (170000<n) {
			cnt = 15493;
			i = 170001;
		}
		if (180000<n) {
			cnt = 16342;
			i = 180001;
		}
		if (190000<n) {
			cnt = 17170;
			i = 190001;
		}



		for (; i <= n; i+=2) {
			for (int j = 3; j <= (int)sqrt(i); j += 2) {
				if (i%j == 0) {
					fg = 1;
					break;
				}
			}
			if (fg)
				fg = 0;
			else
				cnt++;
		}
		if (n == 1)
			cnt--;
		cout << cnt << endl;
	}

	return 0;
}

C++: import math
import sys

def prime_calc(n):
    rootN = int(n**0.5)
    prime = [2]
    data = [i + 1 for i in range(2,n,2)]
    while True:
        p = data[0]
        if rootN <= p:
            return len(prime + data)
        prime.append(p)
        data = [e for e in data if e % p != 0]

def main():
    l = []

    for line in sys.stdin:
        l.append(line)        

    for line in l:
        print(prime_calc(line))

if __name__ == "__main__":
    main()

C++: #include<stdio.h>
int flg[1000000];
int main(void)
{

	int a,i,j,cnt;
	while(scanf("%d",&a)!=EOF){	
		for(i=2;i<=a;i++){
		flg[i]=1;
		}
		for(i=2;i*i<=a;i++){
			if(flg[i]=1){
				j=2;
				while(i*j<=a){
				flg[i*j]=0;
//				printf("i=%d j=%d a=%d\n",i,j,a);
				j++;
				}
			}
		}
//		for(i=2;i<=10;i++)	printf("flg=%d\n",flg[i]);
		cnt=0;
		for(i=2;i<=a;i++){
//		printf("i=%d\n",i);
			if(flg[i]==1){
//			printf("i=%d\n",i);
			
			cnt++;
			}
		}
		printf("%d\n",cnt);
	}	
	return 0;
}

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

void AOJ0009()
{
	int n = 0;
	int prime[10000];
	int count = 0;
	for (int i = 2; i <= 10000; i++)
	{
		int j = 2;
		bool flag = false;
		for (j = 2; j <= i; j++)
		{
			if (i % j == 0)
				break;
		}
		if (i == j)
		{
			prime[count] = i;
			count++;
		}
	}

	while (cin >> n)
	{
		count = 0;
		while (prime[count] <= n)
		{
			count++;
		}
		cout << count << endl;
	}
}
int main()
{
	//AOJ0005();
	//AOJ0007();
	AOJ0009();
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int n;
	while (std::cin >> n)
	{
		std::vector<bool> v(n + 1 ,false);
		int c = 0;
		v[0] = true, v[1] = true;
		for (int i = 2; i * i <= n ; ++i) {
			if (!v[i]) {
				for (int j = i * i; j <= n; j += i) {
					v[j] = true;
					++c;
				}
			}
		}

		std::cout << n-c-1 << std::endl;
	}
}

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

int main(){
int n;
cin >> n;
int a[n+1];
int b;
int c;
b=1;
while(b<n+1){
a[b]=0;
b=b+1;}
a[1]=1;
int d;
d=0;
b=2;
while(b<n+1){
if(a[b]==0){d=d+1; c=2; while(1){if(c*b>n){break;} a[c*b]=1; c=c+1;}}
b=b+1;}


cout << d;


}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string.h>
using namespace std;
const int N=11111;
vector<int> prime;
int sieve(long long n){
   bool arr[n+1];
   int cnt=0;
   memset(arr,true,sizeof(arr));
   for(int i=2;i<=n;++i){
    if(arr[i]){
        prime.push_back(i);
        cnt++;
    }
    for(int j=0;j<prime.size()&&i*prime[j]<n;j++){
        arr[i*prime[j]]=false;
        if(i%prime[j]==0)break;
    }
   }
   return cnt;
}

int main(){
long long num;
int a;
while(true){
    cin>>num;
    if(!num) break;
    a=sieve(num);
    printf("%d\n",a);
}
return 0;
}