Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

static int GetPrimeNumberNum(int maxValue);

int main(void)
{
  int n;
  
  while (std::cin >> n) {
    std::cout << GetPrimeNumberNum(n) << std::endl;
  }
}

static int GetPrimeNumberNum(int maxValue)
{
  std::vector<int> searchList;
  std::vector<int> primeList;
  
  for (int i = 2; i <= maxValue; i++) {
    searchList.push_back(i);
  }
  
  double maxValueSq = sqrt((double)maxValue);
  
  while (true) {
    int newPrime = searchList.at(0);
    
    if (newPrime > maxValueSq) {
      break;
    }
    
    primeList.push_back(newPrime);
    
    for (std::vector<int>::iterator it = searchList.begin();
         it != searchList.end();
         ) {
      if (*it % newPrime == 0) {
        it = searchList.erase(it);
      }
      else {
        ++it;
      }
    }
  }
  
  for (std::vector<int>::iterator it = searchList.begin();
       it != searchList.end();
       ++it) {
    primeList.push_back(*it);
  }
  
  searchList.clear();
  
  return primeList.size();
}

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

int main(){
   bool is_prime[1000000];
   is_prime[0]=is_prime[1]=false;
   for(int i=2;i<1000000;i++)
      is_prime[i]=true;
   for(int i=2;i*i<1000000;i++){
      if(is_prime[i]){
         for(int j=i*i;j<1000000;j+=i){
            is_prime[j]=false;
         }
      }
   }
   int n[1000000];
   int count=0;
   for(int i=0;i<1000000;i++){
      if(is_prime[i])
         count++;
      n[i]=count;
   }
   while(true){
      int x;
      cin >> x;
      if(cin.eof())
         break;
      cout << n[x] << endl;
   }
   
   return 0;
}

C++: #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int up=1000*1000;
int n[up];
bool comp[up];
int main() {
	int r=0;
	for(LL i=2;i<up;i++){
		if(comp[i]==false){
			r++;
			for(LL j=i*i;j<up;j+=i){
				comp[j]=true;
			}
		}
		n[i]=r;
	}
	int k;
	while(cin >> k)
	{
		cout << n[k] << endl;
	}
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt;
    int list[100000];

    cnt=0;
    for (long i=2; i<1000000; i++){
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
	printf("input : ");
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (long i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

inline int IsPrime(int n){
    int i;

    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include<iostream>

using namespace std;

int main(){
    static bool not_prim[1000000];
    static int num_prim[1000000];
    for(int i=2;i<1000000;i++)
    {
        if(!not_prim[i])
        {
            for(int j=2;j*i<1000000;j++)
            {
                not_prim[i*j]=true;
            }
        }
        num_prim[i]=num_prim[i-1]+!not_prim[i];
    }
    int n;
    while(cin >> n){
    cout<<num_prim[n]<<endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <vector>

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		std::vector<int> num;
		int max=2;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(unsigned int i=0;i<count;i++){
				if(m!=num[i] && m%num[i]==0){
					check=false;
					if(max<m){
						max=m;
					}
					break;
				}
			}
			if(check==true){
				if(count>0){
					if(max>num[count-1]){
						for(int i=max+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
					else{
						for(int i=num[count-1]+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
				}
				else{
					for(int i=2;i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							if(max<m){
								max=m;
							}
							break;
						}
					}
				}
			}
			if(check==true){
				num.push_back(m);
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {

	int n;
	int *k;
	
	while (cin >> n) {
		int counter = 0;
		k = (int *)malloc(sizeof(int) * n);
		if (k == NULL) {
			exit(0);
		}
		k[0] = 1;
		for (int i = 1; i < n; i++) {
			k[i] = 0;
		}

		for (int i = 1; i < n; i++) {
			if (k[i] == 0) {
				for (int j = 1; j < i; j++) {
					if (k[j] == 0) {
						if ((i+1) % (j+1) == 0) {
							k[i] = 1;
							break;
						}
					}
				}
				if (k[i] == 0) {
					for (int t = 2; t < n/(i+1); t++) {
						k[(i+1)*t-1] = 1;
					}
				}
			}
		}

		for (int i = 0; i < n; i++) {
			if (k[i] == 0) {
				counter++;
			}
		}

		cout << counter << endl;

		free(k);
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=1e6+5;
int pri[MAX];
bool py[MAX];
int counts[MAX];
void isprime()
{
	memset(py,true,sizeof(py));
	memset(counts,0,sizeof(counts));
	int c=0;
	pri[0]=pri[1]=false;
	for(int i=2;i<=MAX;i++)
	{
		if(py[i])
		{
			counts[i]=++c;
			for(int j=2*i;j<=MAX;j+=i)
			py[j]=false;
		}
		else counts[i]=c;
	}
}
int main()
{
	isprime();
	while(cin>>n) cout<<counts[n]<<endl;
	return 0;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

bool pr[1000000];

template <size_t N>
void psieve(bool (&p)[N]) {
  for (int i = 0; i < N; i++)
    p[i] = true;
  p[0] = p[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!p[i])
      continue;
    for (int j = i * i; j < N; j += i)
      p[j] = false;
  }
}

int solve(int n) {
  int r = 0;
  REP (i, n+1) r += pr[i];
  return r;
}

int main() {
  ios::sync_with_stdio(false);
  psieve(pr);
  int n;
  while (cin >> n) {
    cout << solve(n) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int x;
const int MAX_N = 1000000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];

void 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;
		}
	}
	cout << p << endl;
}

int main()
{
	while (scanf("%d",&x)!= EOF){
		sieve(x);
	}
	
	return 0;
}