Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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;
}

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

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	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;
			}
		}
	}
	for(i=0;i<30;i++){
		scanf("%d", &v);
		int count = 0;
		for(i=0;i<=v;i++){
			int isprime = prime[i];
			if(isprime) count ++;
		}
		printf("%d",count);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	int n, count = 0;
	while(cin >> n) {
		for(int i = 2; i < n + 1; i++) {
			count++;
			for(int j = 2; j <= i / 2; j++) {
				if(i % j == 0) {
					count--;
					break;
				}
			}
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

C++: #include <stdio.h>

int main(void){
int n;
while(scanf("%d",&n)!=EOF){
int count=0;
for(int m=1;m<=n;m++){
bool check=true;
for(int i=2;i<m;i++){
if(i!=m && m%i==0){
check=false;
}
}
if(check==true){
count++;
}
}
}
return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long Int;

const int N = 1000000;
const int M = 1000;
const int K = 6000000;

vector<Int> iterativeSieve(){
    static int p[K], table[M];
    for(int i=2; i<M; i++) p[i] = i;
    for(int i=2; i*i<M; i++){
        if(p[i]){
            for(int j=i*i; j<M; j+=i){
                p[j] = 0;
            }
        }
    }
    p[0] = p[1] = 0;
    int num = remove(p, p+M, 0) - p;
    for(int m=M; m<N; m+=M){
        for(int x=m; x<m+M; x++){
            table[x-m] = x;
        }
        for(int i=0,j; p[i]*p[i]<m+M; i++){
            if(p[i] >= m)          j = p[i] * p[i];
            else if(m % p[i] == 0) j = m;
            else                   j = m - (m % p[i]) + p[i];
            for(; j<m+M; j+=p[i])  table[j-m] = 0;
        }
        num = remove_copy(table, table+M, p+num, 0) - p;
    }
    return vector<Int>(p, p+num);
}

int main(){
    vector<Int> prime = iterativeSieve();
    int n, cnt;

    while(cin >> n){
        cnt = 0;
        for(int i=0; prime[i] <= n && i < prime.size(); i++){
            cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

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

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; RE;}
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)&&prime[i]) {
        ans++;
        for(int j=i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}