Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

int main(){
	int NUM;
	std::list<int> numList,primeList;
	std::cin >> NUM;
	if(NUM<2){
		return 0;
	}
	for(int i=2;i<=NUM;++i){
		numList.push_back(i);
	}
	
	for(int i=numList.front();i<std::sqrt(NUM);i=numList.front()){
		primeList.push_back(i);
		numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
	}
	std::copy(numList.begin(),numList.end(),std::back_inserter(primeList));

	std::cout << primeList.size() << std::endl;

	return 0;
}

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

int main() {
	int N;
	bool is_prime[1000000];
	is_prime[0]=0; is_prime[1]=0;
	for(int i=2;i<1000000; i++){
		is_prime[i]=1;
	}
			
	for(long long s=2; s<1000000; s++){
		if(is_prime[s]==1){	
		for(long long i=s*s; i<1000000; i+=s){
		is_prime[i]=0;	
			
		}
		}
	}
	
	while(cin >> N){
	
		int ans=0;
		for(int i=2; i<N+1; i++){
			ans+=is_prime[i];
		}
		cout << ans <<endl;
		
	}
return 0;
}

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

int main(){

	int i,j,k,n,x;

	while(std::cin >> n){
		x = 1;
		for(i=3;i<=n;i+=2){
			k = 0;
			for(j=3;j<i;j+=2){
				if(i%j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0){
				x++;
			}			
		}
		std::cout << x << std::endl;
	}
}

C++: // #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
// #define DEBUG
#ifdef DEBUG
#define debug(...) printf( __VA_ARGS__ )
#else
#define debug(...)
#endif
#define MEM(x,y) memset(x, y,sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
vector<int> vec;
int a[999999 + 10];
void init(){
	memset(a,0,sizeof a);
	for (int i = 2;i <=  999999 + 9;++i){
		if (a[i] == 0){
			vec.push_back(i);
			for (int j = i + i;j <=  999999 + 9;j += i){
				a[j] = 1;
			}
		}
	}
}
int main()
{	
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int n;
	init();
	while(scanf("%d",&n) != EOF){
		int ans = upper_bound(vec.begin(), vec.end(),n) - vec.begin();
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  int ans,n;
  while (cin >> n) {
    for(int i=2;i<n+1;i++) {
      for(int j=2;j<i+1;j++) {
        if(i == j) {
          ans++;
          break;
        }
        if(i % j ==0) {
          break;
        }
      }


    }
    cout << ans << endl;
    ans = 0;
  }
}

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

int main()
{
  bool p[1000001];
  int n, ans;

  for(int i=0; i<=1000000; i++){
    p[i] = (i<=1)? false : true ;
  }

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

  while( cin >> n ){
    ans = 0;
    for(int i=0; i<=n; i++){
      if(p[i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main() {
	int n,i,k,ans;
	int MAX_V=1000000;
	int prime[MAX_V];
	int sum[MAX_V+1];
	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;
			}
		}
	}
	while(scanf("%d", &n) != EOF) {
		for(i=0;i<=n;i++) {
			sum[i+1]=sum[i]+prime[i];
		}
		ans=sum[n+1];
		printf("%d\n",ans);
	}
	return 0; 
}

C++: #include <iostream>
#define REP(i,n) for(int (i) = 0; i <= n; ++i)
using namespace std;

bool is_prime(int n){
    for (int i = 2; i*i <= n; i++) if(n%i == 0)return false;
    return n>=2;
}

int main() {
    int n;
    while(cin>>n){
        int ret = 0;
        REP(i, n)if(is_prime(i))ret++;
        cout<<ret<<endl;
    }
    return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		int num = 0;
		for (int i = 1; i <= n; i++) {
			if (i <= 3) {
				if (i == 2 || i == 3) num++;
				continue;
			}
			else {
				if (i % 2 == 0 || i % 3 == 0) continue;
				if (i % 6 != 1 && i % 6 != 5) continue;
				bool check = true;
				for (int j = 5; j * j <= i; j += 6) {
					if (i % j == 0) check = false;
					if (i % (j + 2) == 0) check = false;
					if (check == false) break;
				}
				if (check == true) num++;
			}
		}
		cout << num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

bool isPrime(int num);

int main()
{
	int count = 0;
	/*int m = 2, n = 0, num;

	cin >> num;

	int *data = new int[num + 1];
	int *result = new int[num + 1];

	data[0] = 0;
	data[1] = 0;

	do
	{
		for (i = 2 * m; i < num + 1; i += m)
		{

		}
	}
	while
	{

	}*/
	const int N = 1000;
	std::vector<bool> isPrime(N + 1, true);    // ?´???°????????°?????¨??¨ON???
	for (int i = 2; i < N; ++i) {
		if (isPrime[i])
		{   
			count++;

			for (int k = i + i; k <= N; k += i)
				isPrime[k] = false;      // ?´???°????????°????´???°????????°?????¨???OFF???
		}
	}
	return 0;






	
}

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n) != EOF) {
		res = 0;
		while (!Eratos[n]) {
			n--;
		}
		printf("%d\n",Eratos[n]);
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vi prime_count;
void sieve(int max){
    int count = 0;
    vector<bool> table(max + 1, true);
    table[0] = false;
    prime_count.push_back(0);
    table[1] = false;
    prime_count.push_back(0);
    for(int i = 2; i <= max; i++){
        if(table[i]){
            count++;
            for(int j = 2; i * j <= max; j++){
                table[i * j] = false;
            }
        }
        prime_count.push_back(count);
    }
}

int main(){
    int n;
    sieve(1000000);
    while(cin>>n){
        cout << prime_count[n] << endl;
    }
    return 0;
}