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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-10;

int main(){
	vector<int> p;
	bool b;
	int n;

	while(cin >> n){
		p.clear();
		if(n > 1){
			p.push_back(2);
			for(int i = 3; i <= n; i++){
				b = true;
				for(int j = 0; j < p.size(); j++){
					if(p[j]*p[j] > i){
						break;
					}
					if(i % p[j] == 0){
						b = false;
						break;
					}
				}
				if(b){
					p.push_back(i);
				}
			}
		}
		cout << p.size() << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}

	int n;
	cin >> n;

	int c = 0;
	if ( n == 2 )
		c = 1;
	else if( n < 2 )
		c = 0;
	else
	{
		c = 1;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( primes[i] )
				c++;
		}
	}

	cout << c << endl;

	return 0;
}

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

int primes[1000000]={0};


int main(){
    primes[0] = -1;
    primes[1] = -1;
    for(int i=2; i<1000; i++){
        if(primes[i]==-1) continue;
        for(int j=i+1; j<1000000; j++){
            if(j%i==0) primes[j] = -1;
        }
    }
    puts("hoge");
    int n;
    while(-1!=scanf("%d", &n)){
        int ans = 0;
        for(int i=2; i<=n; i++){
            if(primes[i] == 0) ans++;
        }
        cout << ans << endl;
    }
}

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

using namespace std;

int ans = 0;

void Prime_number(int n){
	int i;
	int prime_num;

	for(i = 2; ; i++){
		if(n % i == 0 && n != i){
			break;
		}else if(n == i){
			ans++;
			break;
		}
	}

	if(n != 2){
		Prime_number(n-1);
	}
}

int main(){
	int n;

	while((scanf("%d",&n)) != EOF){
		Prime_number(n);
		cout << ans << endl;
		ans = 0;
	}

}

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

using namespace std;

int main()
{
    int n;
    int prime[800];
    int ptr = 0;

    prime[ptr++] = 2;
    prime[ptr++] = 3;

    while (cin >> n) {
        if (n == 2) {
            cout << "1\n";
            continue;
        }
        else if (n == 3) {
            cout << "2\n";
            continue;
        }

        int count = 2;        
        for (int i = 5; i <= n; i += 2) {
            bool flag = false;
            for (int j = 1; prime[j] * prime[j] <= i; j++) {
                if (!(i % prime[j])) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                prime[ptr++] = i;
                count++;
            }
        }
        cout << count << "\n";
    }
    
    return 0;
}

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

int main (void){
	int number, i, j, count=0;
	
	while(scanf("%d", &number)!=EOF){
	count=0;
	int n[number];
	for(i=0; i<number; i++){
		n[i]=i;
	}
	
	for(i=0; i<number; i++){
		j=i;
		while(1){
			j+=i;
			if(j>number){break;}
			n[j]=-1;
			if(i==0 || i==1){
				n[i]=-1;
				break;
			}
		}
	}
	
	for(i=0; i<number; i++){
		if(n[i]!=-1){
			//printf("%d\n", n[i]);
			count++;
		}
	}
	printf("%d\n", count+1);
	}
	
	return 0;
}

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

bool f(int n)
{
     bool flag = true;
     for(int j=2; j<n; j++)
     {
         if(n%j == 0)
             flag = false;
     }
     if (flag == true)
         return 1;
     else
         return 0;
}

int main()
{
    int n, sum;
        
    while(cin >> n)
    {
        sum = 1;
        if(n<2)
            cout << 0;
        else if(n==2)
            cout << 1;
        else
        {
            for(int i=3; i<=n; i++)
                if(f(i))
                    sum++;
            
            cout << sum;
        }
        cout << endl;
    }
    
    return 0;
}

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

vector<char> sieve(const int M){
    vector<char> isPrime(M);
    for(int i=2;i<M;i++) isPrime[i] = true;
    for(int i=2;i*i<M;i++){
        if(not isPrime[i]) continue;
        for(int j=i*i;j<M;j+=i){
            isPrime[j] = false;
        }
    }
    return isPrime;
}

int main (int argc, char const* argv[])
{
    int n;
    vector<char> p;
    while(cin >> n){
        int count = 0;
        p = sieve(n+1);
        for(vector<char>::iterator it = p.begin(); it != p.end() ; ++it){
            if(*it == true)
                ++count;
        }
        
        cout << count << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
	inline char getchar() {
		static const int BUFSIZE=5201314;
		static char buf[BUFSIZE],*begin,*end;
		if(begin==end) {
			begin=buf;
			end=buf+fread(buf,1,BUFSIZE,stdin);
			if(begin==end) return -1;
		}
		return *begin++;
	}
}
inline void read(int &in) {
	int c,symbol=1;
	while(isspace(c=IO::getchar()));
	if(c=='-') { in=0;symbol=-1; }
	else in=c-'0';
	while(isdigit(c=IO::getchar())) { in*=10;in+=c-'0'; }
	in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n';

const int maxn=1e6+10;
int pr[maxn];
char vis[maxn];
int n;

int main() {


    memset(vis,1,sizeof(vis));
    vis[0]=vis[1]=false;
    For(i,2,maxn) if(vis[i]){
        int j=i*2;
        while(j<=maxn) vis[j]=false,j+=i;
    }
    For(i,2,maxn) pr[i]=pr[i-1]+vis[i];
    while(scanf("%d",&n)==1) printf("%d\n",pr[n]);


	return 0;
}

C++: #include <iostream>
#include <math.h>
 
#define N 1000000
 
using namespace std;
 
int main(){
    bool prm[N];
    for(int i=0;i<N;i++)prm[i]=true;
    int upto = (int)sqrt(N);
    for(int i=2;i<=upto;i++){
        if(prm[i]){
            for(int j=2;i*j<=N;j++) prm[i*j] = false;
        }
    }
    int n;
    while(cin >> n){
        int count = 0;
        for(int i=2;i<=n;i++){
            if(prm[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}