Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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

int main()
{
    bool *table = new bool[1000000];
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        memset(table, 1, sizeof(bool) * (n + 1));
        for (int i = 2; i * i <= n; ++i)
            for (int j = 2; i * j <= n; ++j)
                table[i * j] = false;

        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += table[i];
        std::cout << cnt << std::endl;
    }
    delete[] table;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a[100001] = {0};
	for(int i = 0; i < 100001; i++){
		a[i] = 1;
	}
	a[0] = 0;
	a[1] = 0;
	for(int i = 0; i < 100; i++){
		if(a[i]){
			for(int j = i * 2; j < 100001; j += i){
				a[j] = 0;
			}
		}
	}

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

	return 0;
}

C++: #include<stdio.h>

int s[1000000] = {0};

int main(){
	int a,b,c,d,e;
	int temp;
	int cont = 0;
	
	while(scanf("%d",&a) != EOF){
		/*
		for(int i = 0; i < a; i++){
			s[i] = 1;
		}
		*/
		
		cont = 0;
		
		s[0] = 1;
		s[1] = 1;
		
		for(temp = 2; temp < a+1; temp++){
			if(s[temp] == 0){
				for(b=temp; b <= a; b+= temp){
					if(b == temp){
						s[b] = 0;
					}
					else{
						s[b] = 1;
					}
				}
			}
		}
		
		for(c = 0; c < a+1; c++){
			if(s[c] == 0){
				
	//		printf("%d\n",c);
				cont++;
			}
		}
		
		printf("%d\n",cont);
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	int x = 1000000;
	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 = 0;
	for(int i=2;i<x;i++) if(q[i]==0) p[c++] = i;
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=0;i<c-1;i++){
			if(p[i]>a) break;
			a++;
		}
		cout << a << endl;
	}
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX_N 999999
int main()
{
    int n;
    bool notPrime[MAX_N+2];
    int count[MAX_N+2];
    for (int i = 2 ; i <= MAX_N ; i++)
    {
        if (!notPrime[i])
        {
            for (int g = i+i ; g <= MAX_N ; g += i)
            {
                notPrime[g] = true;
            }
        }
    }
    int cnt = 0;
    count[1] = 0;
    for (int g = 2 ; g <= MAX_N ; g++)
    {
        if (!notPrime[g])
            cnt ++;
        count[g] = cnt;
    }
    for(int n;cin>>n;n++){
        cout<<count[n]<<endl;
    }
    
}

C++: #include <iostream>

using namespace std;

#define MAX 1000000

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

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

int main(){

  int n;
  int a,i,count;
  while(cin >> n){
    if(n < 1000000){
      count = 0;
      for(;1<n;n--){
	for(a=2,i=1;a<=n/2;a++)
	  if(n%a == 0){
	    i = 0;
	    break;
	  }
	if(i)
	  count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}

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

int main()
{
	int n = 0, x = 0;
	int countdata[1000];
	while (cin >> n) {
		int count = 0;
		for (int a = 2; a <= n; a++) {
			int count2 = 0;
			if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a % 7 != 0) {
				count++;
			}
			else {
				for (int b = 2; b <= a / 2; b++) {
					if (a%b != 0)
						count2++;
				}
				if (count2 == a / 2 - 1)
					count++;
			}
		}
		countdata[x] = count;
		x++;
	}
	for (int a = 0; a < x; a++) {
		cout << countdata[a] << endl;
	}
}

C++: #include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
int main(void) {
  int num;
  while(scanf("%d", &num)==1) {
    vector<int> A;
    int ans;
    int count = 0;
    for (int i = 0; i < num - 1; i++) {
      A.push_back(i+2);
    }
    for (int i = 0; i < num - 1; i++) {
      if(A[i] != 0) {
      int k = 2;
      while(k*A[i] < num + 1) {
        if(A[k*A[i]-2] != 0) {
          A[k*A[i]-2] = 0;
          count++;
        };
        k++;
      }
    }
      if(i > sqrt(num)) break;
    }
    ans = num - 1 - count;
    printf("%d\n",ans);
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 1000000

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

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <iostream>
#include <string.h>
#include <map>
#include <set>
#include <functional>

using namespace std;

const int INF = (1<<30) - 1;


int main(){
    int n = 1000000;
	vector<bool> is_prime(n, true);
    vector<int> count(n);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<n; i++){
        if(is_prime[i]){
            for(int j=i; j<n; j+=i)
                is_prime[j] = false;
            count[i]++;
        }
        count[i] += count[i-1];
    }
    
    int a;
    while(cin>>a){
        cout << count[a] << endl;
    }
    
	return 0;
}

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

bool IsPrime(int p)
{
	for (int i = 2; i <= sqrt(p); i++)
	{
		if (p % i == 0) return false;
	}
	return true;
}

int main()
{
	int n;
	while (cin >> n)
	{
		int ans = 0;
		for (int i = 2; i <= n; i++)
		{
			if (IsPrime(i)) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    const int N = 1000000;
    vector<bool> vec(N, true);
    int limit = 1000;
    for (int i = 2; i < limit; i++){
        for (int j = 2; i * j < N; j++){
            vec[i * j] = false;
        }
    }
    int n, cnt = 0;
    while (cin >> n){
        for (int i = 2; i <= n; i++){
            if (vec[i])cnt++;
        }
        cout << cnt << endl;
        cnt = 0;
    }
}

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

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=999999;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

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

using namespace std;

const int N_MAX = 1000000;
int table[N_MAX];

int main() {
  table[0] = table[1] = 1;
  int sq = sqrt(N_MAX);
  for (int i = 2; i < sq+1; i++) {
    if (table[i] == 0) {
      for (int j = i*2; j < N_MAX; j += i) {
        table[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {

    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (table[i] == 0) ans++;
    }
    cout << ans << endl;

  }

  return 0;
}