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>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isprime (int n){

	if (n == 0 || n == 1){
		return false;
	}else if (n == 2){
		return true;
	}else if (n % 2 == 0){
		return false;
	} // end if
	
	for (int i = 3; i <= sqrt(n); i+= 2){
		if (n % i == 0){
			return false;
		} // end if
	} // end for
		
	return true;
}

int main()
{
	
//	cut here before submit 
//	freopen("testcase.prime", "r", stdin);
	int res = 0;
	string str = "";
	int n;

	getline (cin, str );
	stringstream ssn(str);
	ssn >> n;
	vector <int> prime(n+1, 0);

	int i;
	int count = 1;
	prime[2] = count;

	for (i = 3; i <= n; i += 2){
		if (isprime(i)){
			++count;
		} // end if
		prime[i] = count;
	} // end for
	res = prime[n];

	cout << res << endl; 

	return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	
	for (int i = 2; i <= MAX; i++){
		if (!vis[i]){

			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;

			}
		}
	}
	int sum = 0;
	for (int i = 2; i <= MAX; i++){
			if (prime[i]){
				sum++;
			}
			amount[i] = sum;
		}

	int n;
	cin >> n;
		cout << amount[n]<< endl;
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    vector<int> vi;
    vi.push_back(2);
    vi.push_back(3);
    for(int i=5;i<=n;i+=2){
      for(int j=3;j<=i;j+=2){
	if(i==j)
	  vi.push_back(i);
	if(i%j==0)
	  break;
      }
    }
    cout<<vi.size()<<endl;
  }
  return 0;
}

C++: 
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int n, count,k;

	while(cin >> n){
		count = 1;
		k = 0;

		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j <= sqrt((double)i); j += 2)
			{
				if(i%j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0){
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <climits>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <deque>
#include <list>
#include <map>
#include <set>
using namespace std;

/*** typedef ***/
typedef long long LL;
typedef unsigned int ui;
typedef unsigned long long ULL;
typedef pair < int , int > ii;
typedef pair < LL  , LL  > ll;
typedef vector <int>  vint;
typedef vector <bool> vbool;
typedef vector <long> vlong;

/*** define ***/
#define sz(x)			((int)x.size())
#define tin(x)			scanf("%d",&x)
#define all(x)			x.begin(),x.end()
#define Set(b,a)		memset(b,a,sizeof b)
#define print1(x)		printf("Case %d:",x++)
#define tin2(x,y)		scanf("%d%d",&x,&y)
#define tin3(x,y,z)		scanf("%d%d%d",&x,&y,&z)
#define loop(i,i0,in)	for(int i=i0 ; i<in ; i++)
#define rep(i,n)		for(int i=0 ; i<(n) ; i++)
#define _rep(i,n)		for(int i=n-1 ; i>=0 ; i--)
#define _loop(i,in,i0)	for(int i=in-1 ; i>=i0 ; i--)
#define Fore(it, x)		for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)

const int       maxn = 1000000+4;
const long double PI = 3.1415926535897932384626433832795;

int mp[maxn];
bool prime[maxn];

void sieve(int n){
	int cnt=0;
	Set(prime,0);
	prime[0]=prime[1]=1;
	loop(i,2,n){
		if(!prime[i]){
			mp[i]=++cnt;
			if(n/i>=i)
				for(int j=i*i ; j<=n ; j+=i)
					prime[j]=1;
		}
		else
			mp[i]=cnt;
	}
}

     
int main()  
{  
#ifdef Online_Judge
	freopen("a.in","r",stdin);
#endif
	int n;
	sieve(1000000);
	while(~tin(n))
		printf("%d\n",mp[n]);
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int count;
	while (1)
	{
		cin >> n;
		if (cin.fail()) break;

		bool *isPrime;
		isPrime = new bool[n + 1];
		memset(isPrime, true, sizeof(bool) * (n + 1));
		isPrime[0] = isPrime[1] = false;
		
		count = 0;
		for (int i = 2; i <= n; ++i)
		{
			for (int j = i + i; j <= n; j += i)
			{
				isPrime[j] = false;
			}
		}
		for (int i = 0; i <= n; ++i)
		{
			if (isPrime[i] == true)
				++count;
		}
		cout << count << endl;
		delete[] isPrime;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int x = 1000001;
	int p[x],q[x];
	for(int i=2;i<x;i++) p[i] = 0;
	for(int i=2;i<x;i++){
		if(q[i]==0) for(int j=2;j<x/i;j++) q[i*j] = 1;
	}
	int c = -1;
	for(int i=2;i<x;i++){
		if(q[i]==0){
			c++;
			p[c] = i;
		}
	}
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=0;i<c;i++){
			if(p[i]>n) break;
			a++;
		}
		cout << a << endl;
	}
}

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

int main(){
  int n;
  int num[1000000]={0};
  num[0]=1;
  num[1]=1;

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

  while(scanf(" %d",&n)!=EOF){
    int cnt=0;
    for(int i=2;i<=n;i++){
      if(num[i]==0){
	cnt++;
      }
    }
    cout << cnt << endl;
  }

  return 0;

C++: #include<stdio.h>

int main(){
	int n=0,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0) p=true;
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	}
	return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i <=MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i+i; j <=MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}