Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: #include <iostream>
int main(int argc, const char * argv[])
{

    // insert code here...
    
    while(true)
    {
        int n;
        std::cin >> n;
        if(std::cin.eof())break;
        
        int count = 0;
        std:
        for(int i=2;i<n;i++)
        {
            bool flag = true;
            for(int j=2;j<i/j+1;j++)
            {
                if(i%j==0)
                {
                    flag=false;
                    break;#include <iostream>
int main(int argc, const char * argv[])
{

    // insert code here...
    
    while(true)
    {
        int n;
        std::cin >> n;
        if(std::cin.eof())break;
        
        int count = 0;
        std:
        for(int i=2;i<n;i++)
        {
            bool flag = true;
            for(int j=2;j<i/j+1;j++)
            {
                if(i%j==0)
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                count++;
            }
        }
        
        std::cout << count <<"\n";
        
    }
    
    return 0;
}


                }
            }
            if(flag)
            {
                count++;
            }
        }
        
        std::cout << count <<"\n";
        
    }
    
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const double PI = 3.141592653589793238462643383279502884L;
const int LARGE_INT = 1000000007;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i,a,cont,next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i,a,b,s) repfn(i,a,i<b,i+s)
#define repab(i,a,b) repby(i,a,b,1)
#define rep(i,b) repab(i,0,b)
#define pb push_back
#define sz(c) int((c).size())

int check(vector<bool> &v, int from, int to)
{
  int i;
  for (i = from + 1; i*i <= to && i*i < sz(v); i++) {
    if (v[i]) {
      for (int j = 2; i*j < sz(v); j++) {
        v[i*j] = false;
      }
    }
  }
  return i - 1;
}

int count(vector<bool> &v, int to)
{
  int res = 0;
  repab (i, 2, to+1) {
    if (i >= sz(v))
      break;
    if (v[i])
      res++;
  }
  return res;
}

int main(int argc, char **argv)
{
  const int prime_max=1000000;
  vector<bool> v(prime_max, true);
  int done;

  int n;
  done = 1;
  while (cin >> n) {
    done = check(v, done, n);
    cout << count(v, n) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{
	while(true) {
		int n;
		cin >> n;
		cout << sieve(n) << endl;
	}
}

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]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return p;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
vector<bool> GetPrimeTable(int n)
{
	vector<bool> IsPrimeNumber(n+1, true);
	for(int i = 2; i <= n; i++){
		while(IsPrimeNumber[i] == false){
			i++;
		}
		for(int j = 2; i*j <= n; j++){
			IsPrimeNumber[i*j] = false;
		}
	}
	return IsPrimeNumber;
}

int GetPrimeCount(vector<bool>& IsPrimeNumber, int n)
{
	int Count = 0;
	for(int i = 2; i <= n; i++){
		if(IsPrimeNumber[i] == true){
			Count++;
		}
	}
	return Count;
}

int main()
{
	vector<int> Input;
	while(true){
		int Nubmer;
		cin >> Nubmer;
		if(cin.eof() == true) break;
		Input.push_back(Nubmer);
	}
	int MaxNumber = *std::max_element(Input.begin(), Input.end());
	vector<bool> IsPrimeNumber = GetPrimeTable(MaxNumber);
	for(int i = 0; i < Input.size(); i++){
		cout << GetPrimeCount(IsPrimeNumber, Input[i]) << endl;
	}
	return 0;
}

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

typedef int TInt;
typedef std::vector<TInt> TList;
bool IsPrime(TInt Value, const TList& Prime)
{
    TInt Max = std::sqrt(Value);
    for(TList::const_iterator It = Prime.begin();
        It != Prime.end() && *It <= Max;
        ++It)
    {
        if(Value % (*It) == 0) return false;
    }
    return true;
}
TList GetPrimeList(TInt Max)
{
    TList Prime;
    Prime.reserve(Max);
    Prime.push_back(2);
    for(TInt i = 3; i <= Max; i += 2){
        if(IsPrime(i, Prime)){
            Prime.push_back(i);
        }
    }
    return Prime;
}
int main()
{
    TList List = GetPrimeList(999999);
    while(true){
        int n;
        std::cin >> n;
        if(std::cin.eof()) break;
        TList::iterator It = std::upper_bound(List.begin(), List.end(), n);
        std::cout << std::distance(List.begin(), It) << std::endl;
        
    }
    return 0;
}

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

using namespace std;

inline void era(vector<bool> &prime, int num);

using namespace std;

int main(void){
  int num;

  while(cin >> num){
    vector<bool> prime((num+1), true);
    prime[0] = false;
    prime[1] = false;
    era(prime, num);
    cout << count(prime.begin(), prime.end(), true) << endl;
  }
  return 0;
}

void era(vector<bool> &prime, int num){
  int N = 2;
  while (N <= num){
    int count = 2;
    while ((count*N) <= num){
      prime[count*N] = false;
      ++count;
    }
    ++N;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1000000+10;
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int ans=0;
        for(int i=2;i<=n;i++){
            if(!notprime[i])
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}