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;
int main(){
	int a,o=0;
	bool n[1000000];
	for(int i=2;i<=999999;i++){
		n[i]=true;
	}
	n[0]=n[1]=false;
		for( int j=2;j*j<=999999;j++){
			if(n[j]){
				for(int k=j*2;k<=999999;k+=j){
				n[k]=false;
				}
			}
		}
		while(cin>>a){
	for(int k=2;k<=a;k++) if(n[k]) o++;
	cout<<o<<endl;
	o=0;
		}
}

C++: #include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    while(scanf("%d", &num) != EOF){
        int count=0;
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;


vector<int> p;
int main(void){
    p.pb(2);
    for(int i = 3; i <1000000; i += 2){
        int j;
        for(j = 0; p[j] * p[j] <= i; ++j){
            if(i % p[j] == 0) break;
        }
        if(i % p[j] > 0) p.pb(i);
    }
    int n;
    while(cin >> n){
        if(n == 1){
            cout << 0 << endl;
            continue;
        }
        int l = 0, r = p.size();
        while(l + 1 != r){
            int t = (l + r)/2;
            if(p[t] <= n) l = t;
            else r = t;
        }
        int ret = r + 1;
        while(n < p[ret]) ret--;
        cout << ret + 1<< endl;
    }
    return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <map>
 
inline bool fermat_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
    }
}
 
inline bool prime_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
            if ((n %= i) == 0) {
                return false;
            }
        }
    }
    return true;
}
 
int main() {
    std::map<int, int> m;
    m[3] = 2;
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 5; i <= n; i += 2) {
            if (m.count(i) > 0)
                continue;
 
            m[i] = m[i - 2] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", m[n % 2 == 0 ? n - 1 : n]);
    }
}

C++: int primes[78498], num_primes;
int calculated;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	calculated = 2;
	num_primes = 1;
	while (true) {
		int n;
		if (!scanf("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				int max = (int)(sqrt(i)) + 1;
				for (int j=1; primes[j] < max&&j<num_primes; j++) {
					if (i%primes[j] == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{

long long  n,f=1,c=0;
cin>>n;
for(long long i=2;i<=n;i++)
{
    if(i==2){f=1;c++;continue;}
    for(long long j=2;j<i;j++)
    {
        if(i%j==0){f=0;break;}
        else f=1;
    }
    if(f==1)c++;
}
cout<<c;
    return 0;
}

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

int a[1000000];

int main()
{
  int n;
  int count;

  for (int i = 2; i < 1000000; i++){
     a[i] = 1;
   }

   for (int i = 0; i * i < 1000000; i++){
     if  (a[i] == 1){
       for (int j = 2; j * i <= 100000; j++){
         a[j * i] = 0;
       }
     }
   }

   while (cin >> n){
     count = 0;
     for (int i = 0; i < 1000000; i++){
       if (a[i] == 1){
         count++;
       }
     }
   }

   cout << n << endl;

   return (1);
}

C++: 
#include<iostream>
#pragma warning(disable:4996)
#define MAX_N 1000000
using namespace std;

int prime[MAX_N];//第i个素数
bool is_prime[MAX_N + 1];//is_pime[i]?true表示i?素数

//返回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) != EOF){
		printf("%d\n", sieve(n));
	}

}

C++: #include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
int prime[maxn];
bool is_prime[maxn];
int sieve(int n) {
	int p = 0;

	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;
	for(int i=0; i<=maxn; i++) is_prime[i] = true;
	//0???1???????´???°
	is_prime[0] = is_prime[1] = false;
	while(~scanf("%d",&n)) {

		int p = sieve(n);
		printf("%d\n",p);
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define NUM 1000000
int main(){
	long int n;
	int p[NUM],i,j,k,a,b;
	for(i=0;i<NUM;i++){
		p[i]=0;
	}
	for(i=2;i<NUM;i++){
		if(p[i]==0){
			p[i]=2;
			for(j=2;j<(NUM/i);j++){
				p[i*j]=1;
			}
		}	
	}
	while(cin>>n){
		a=0;
		for(i=2;i<=n;i++){
			if(p[i]==2)a++;
		}
		cout<<a<<endl;
	}
    return 0;
}