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 <vector>
#include <list>
#include <algorithm>
#include <cmath>
using namespace std;

void sieve(int n, list<int> &primes)
{
    vector<bool> v(n / 2 + 1, true);

    // check
    for (int i = 3, end = sqrt(n); i <= end; i += 2) {
        if (!v[i / 2])
            continue;
        for (int j = i * i / 2; j <= n / 2; j += i)
            v[j] = false;
    }

    primes.push_back(2);
    for (int i = 1; i <= n / 2; i++)
         if (v[i])
            primes.push_back(i * 2 + 1);
}

int main()
{
    list<int> primes;
    vector<int> inputs;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        int count = 0;
        for (auto p : primes) // find
            if (p == x) {
                count++;
                break;
            } else if (p > x)
                break;
            else
                count++;
        cout << count << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 999999;
bool p[MAX_N+1];
int sum[MAX_N+1];

void make_prime (void )
{
	fill (p, p+MAX_N+1, true );
	memset (sum, 0, sizeof (sum ) );
	p[0] = false;
	p[1] = false;
	for (int i = 2; i <= MAX_N; i++ ){
		if (p[i] ){
			for (int j = 2*i; j <= MAX_N; j += i ){
				p[j] = false;
			} // end for
		} // end if
	} // end for

	for (int i = 1; i <= MAX_N; i++ ){
		sum[i] = sum[i-1] + (p[i] ? 1 : 0 );
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.PN", "r", stdin );
	make_prime ();

	string str = "";
	while (getline (cin, str ) ){
		stringstream ss (str );
		int n;
		ss >> n;
		printf ("%d\n", sum[n] );
	} // end while

	return 0;
}

C++: #include<iostream>
#include<string>
#include<math.h>
using namespace std;

bool p[1000000];

int main(){
	int c,n;
	while(cin >> n){
		c = 0;
		for(int i = 2; i <= sqrt(n); i++){
			for(int j = 2; i * j <= n; j++){
				p[i*j] = true;
			}
			
		}
		for(int i = 2; i <= n; i++){
			if(p[i] == 0){
				c++;
				
			}
		}
		cout << c << endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <array>
&#160;
int main() {
&#160;&#160;&#160;&#160;std::array<bool, 1000000> is_prime_table = { false, false, true };
&#160;&#160;&#160;&#160;for( int i=3; i<=is_prime_table.size(); i+=2 ) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;is_prime_table[i] = [&i]() -> bool
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for( int j=3; j*j<=i; j+=2 )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ( i % j == 0 )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return false;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return true;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}();
&#160;&#160;&#160;&#160;}
&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;int num = 0;
&#160;&#160;&#160;&#160;while( std::cin >> num ) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;int result = num > 1 ? 1 : 0;&#160;&#160;&#160; // 2
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for( int i=3; i<=num; i+=2 )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if ( is_prime_table[i] )
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;++result;
&#160;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;std::cout << result << std::endl;
&#160;&#160;&#160;&#160;}
}

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

using namespace std;

long* primes(long high)
{
  long* p = new long[high];
  for (int i = 0; i < high; i++) {
    p[i] = 0;
  }

  long max = ceil(sqrt(high));
  for (int i = 2; i <= max; i++) {
    if (p[i - 1] == -1) continue;

    int count = 2;
    while (i * count <= high) {
      p[i * count - 1] = -1;
      count++;
    }
  }

  for (int i = 1; i < high; i++) {
    if (p[i] == -1) {
      p[i] = p[i - 1];
    } else {
      p[i] = p[i - 1] + 1;
    }
  }
  
  return p;
}

int main(int argc, char const* argv[])
{
  long* p = primes(999999);
  long n;

  while (cin >> n) {
    cout << p[n - 1] << endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int d[1000000]={},p[1000000]={};
int main(){
	int n;
	for(int i=2;i<1000000;i++){
		if(d[i]==0){
			for(int j=2;i*j<1000000;j++){
					d[i*j]=1;
			}
		}
	}
	for(int i=2;i<1000000;i++){
		if(d[i]==0)
		p[i]=p[i-1]+1;
		else
		p[i]=p[i-1];
	}
	while(cin>>n,n){
		cout<<p[n]<<endl;;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main()
{int n;
 while(scanf("%d",&n))
 {int sum=1;
  int i;
  for(int m=3;m<=n;m++)
  {if(m%2==0)continue;
	  int k=int (sqrt(double(m)));
	  i=2;
   while(m%i&&i<=k)
	   i++;
   if(i>k)sum++;
  }
  printf("%d\n",sum);
 }
}

C++: #include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		n += 1;
		bool *p = new bool[n];
		fill(p, p + n, true);
		p[0] = p[1] = false;
		for (int i = 2; i * i < n; i++)
			if (p[i] == true)
				for (int j = i * i; j < n; j += i)
					p[j] = false;
		for (int i = 0; i < n; i++)
			if (p[i] == true)
				ans++;
		cout << ans << endl;
		delete[] p;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
	vector<int> array;
	int n;
	bool f;
	cin >> n;
	for(int i=2;i<=n;i++){
		f=true;
		for(int j=0;j<array.size();j++)
		if(!(i%array[j])){
		f=false;
		continue;
	}
		if(f==true)array.push_back(i);
	}
	cout << array.size();
	return 0;
}