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>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while (cin)
	{
		int tmp;

		cin >> tmp;

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		//if (cin.eof()) { break; }
	}

	return 0;
}

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

const int MAX_N = 1000000;

int cnt = 0;
int prime[MAX_N], vis[MAX_N];

void init() {
  memset(vis, 0, sizeof(vis));
  int m = sqrt(MAX_N + 0.5);
  for (int i = 2; i <= m; i++) if (!vis[i]) {
    for (int j = i * i; j <= MAX_N; j += i) {
      vis[j] = 1;
    }
    prime[cnt++] = i;
  }
}

int main() {
  init();
  int n;
  while (scanf("%d", &n) == 1) {
    printf("%ld\n", upper_bound(prime, prime + cnt, n) - prime);
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

bool sosu(int n)
{
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

int main(void)
{
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(sosu(i))
				ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include<stdio.h>
const int MAX_V=10000;
int prime[MAX_V+1];
int main(){
  int i,k,n,p,q,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;
      }
    }
  }
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(v=2;v<=n-2;v++){
      int isprime=prime[v]*prime[v+2];
      if(isprime)p=v,q=v+2;
    }
    printf("%d %d\n",p,q);
  }
  return 0;
}

C++: #include<stdio.h>

int pr[78498];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
      return nxp;
    }else{
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i,j=0;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF&&j<30){
        /*printf("n=%d\n",n);*/
        i=0;
        if(n-1){
            while(pr[i]<=n){
                /*printf("prime:%d(%d)\n",pr[i],i+1);*/
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
        j++;
    }
}

C++: #include<vector>
#include<algorithm>

std::vector<int> primeNumbers = {2, 3};
std::vector<bool> isPrime;

void eratosthenes(int n){
    int i, j;
    int s = 4;

    isPrime.assign(std::max(n + 1, 2), true);
    isPrime[0] = false;
    isPrime[1] = false;

    for(i = 4 ; i <= n ; i += 2){
        isPrime[i] = false;
    }
    for(i = 9 ; i <= n ; i += 6){
        isPrime[i] = false;
    }

    for(i = 5 ; i * i <= n ; i += s){
        if(isPrime[i]){
            primeNumbers.emplace_back(i);
            for(j = i * i ; j <= n ; j += i){
                isPrime[j] = false;
            }
        }
        s ^= 6;
    }
    for( ; i <= n ; i += s){
        if(isPrime[i]){
            primeNumbers.emplace_back(i);
        }
        s ^= 6;
    }

    return;
}

#include<iostream>

int main(){
    eratosthenes(999999);

    int n;
    while(std::cin >> n){
        std::cout << std::upper_bound(primeNumbers.begin(), primeNumbers.end(), n) - primeNumbers.begin() << std::endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
#define MAXNUM 1000000
using namespace std;

int num[MAXNUM]={0};

int main(){
  int n;
  while(cin >> n){
    vector<int> vec;
    vec.push_back(2);
    for(int i = 3; i<=n; i+=2){
      if(num[i]==1) continue;
      FOR(j, 2, MAXNUM){
        if(i*j>=n)  break;
        num[i*j]=1;
      }
      vec.push_back(i);
    }
    cout << vec.size() << endl;
  }
  return 0;
}

C++: #include<stdio.h>
const int MAX_N=99999;
bool is_prime[MAX_N+1];

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]){
            p++;
            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));
   }
   return 0;
}

C++: #include <stdio.h>

int main(void){
	bool a[1000000];
	int n = 0;
	int c = 0;
	while(scanf("%d", &n) != EOF){
		switch(n){
		case 1:
			c = 0;
			break;
		case 2:
			c = 1;
			break;
		default:
			c = 1;
			for(int i=3; i<=n; i+=2){
				a[i] = true;
			}
			for(int i=3; i<=n; i+=2){
				if(a[i] == false){ continue; }
				c++;
				for(int j=i; j<=n; j+=i){
					a[j] = false;
				}
			}
			break;
		}
		printf("%d\n", c);
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#define DB(x) 
int prime[80000];
int GetPrime(int num);

int main(){
	int count = GetPrime(1000000);
	DB(printf("%d\n",count));
	int n,ans[100],cor = 0;
	int i;
	while(scanf("%d",&n) != EOF){
		for(i = 0;n >= prime[i] && i < count;i++);
		ans[cor] = i;
		cor++;
	}
	for(i = 0;i < cor;i++)
		printf("%d\n",ans[i]);
	return 0;
}

int GetPrime(int num){
	int i,j,count = 0;
	int sqnum = sqrt((double)num);
	for(i = 2;i <= num;i++){
		for(j = 0;j < count;j++){
			if(prime[j] > sqnum)
				goto COUNT;
			if(i%prime[j] == 0)
				break;
		}
		if(j < count)
			continue;
		COUNT:
		prime[count] = i;
		count++;
	}
	return count;
}

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

using namespace std;

int sum[1000001];
bool prime[1000001];

void sieve()
{
	fill_n(prime, 1000001, true);

	prime[1] = false;

	for (int i = 2; i <= 1000000; ++i) {
		sum[i] = sum[i - 1];
		if (!prime[i]) continue;
		sum[i]++;
		for (int k = i + i; k <= 1000000; k += i) {
			prime[k] = false;
		}
	}
}

int main()
{
	sieve();

	int n;
	
	while (~scanf("%d", &n)) printf("%d\n", sum[n]);
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

bool p[1000000];

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