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 <cstdio>
using namespace std;

const int MAX_N = 999999;
bool prime[MAX_N + 1];

void sieve()
{
  prime[0] = prime[1] = false;
  for(int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  for(int i = 2; i <= MAX_N; ++i)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
}

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n, i;
  int ans = 0;
  sieve();
  while(cin >> n){
    for(i = 0; i < n; i++){
      if(is_prime(i)){
	ans++;
      }
    }
    if(i == n){
      break;
    }
  }
  printf("%d\n", ans);
}

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

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

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

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

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

int main(){
  int a;
  int i, j, k;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=2; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        for(j=i; j<=a/i; j++){
          chk[j*i]=false;
        }
      }
      past=a;
      for(i=2; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

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

using namespace std;
   
void primeCal()
{
    const int N = 1000000;
    
    vector<bool> prime(N, true);
    prime[0] = prime[1] = false;
    
    vector<int> count(N);
    
    int n;
    
    for (int i = 2; i*i < N; ++i) 
    {
        if (!prime[i]) 
        { 
            continue; 
        }
        
        for (int j = i*i; j < N; j += i) 
        {
            prime[j] = false;
        }
    }
    
    for (int i = 1; i < N; ++i) 
    {
        count[i] = count[i-1] + prime[i];
    }
    
    while (cin>>n)
    {
        cout << count[n] << endl;
    }
    
    return;
}
     
int main()
{     
    primeCal();
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n,i,j;
	
	while(cin>>a){
	n=0;
	for(i=2;i<=a;i++){
		for(j=2;j<i;j++){
			if(i%j==0)break;
		}
		if(i == j) n += 1;
	}
	cout<<n<<endl;
	n=0;
	}
	
}

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

int prime[1000000];

int main()
{
  int n;
  for (int i = 0; i < 1e6; i++) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 1000000; i++){
    if (prime[i] == 1){
      for (int j = 2 * i; j < 1000000; j += i){
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 1000000; i++){
    prime[i + 1] += prime[i];
  }
  while (cin >> n){
    cout << prime[n] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	long prime[80000];
	prime[0] = 2;
	int num = 1;
	for (int i = 3; i < sqrt(1000000); i += 2) {
		if (isprime(i)) {
			prime[num] = i;
			num++;
		}
	}
	long n; while (cin >> n) {
		int j = 0;
		for (; prime[j] <= n; j++) {}
		cout << j << endl;
	}
	return 0;
}

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

using namespace std;

bool table[1000000];
vector<int> primes;

int main() {
  table[2] = true;
  for (int i = 3; i <= 999999; i += 2)
    table[i] = true;
  for (int i = 3; i <= 1000; i += 2)
    if (table[i])
      for (int j = 3 * i; j <= 999999; j += 2 * i)
        table[j] = false;
  primes.push_back(2);
  for (int i = 3; i <= 999999; i += 2)
    if (table[i])
      primes.push_back(i);
  int n;
  while (scanf("%d", &n) == 1) {
    printf("%d\n", upper_bound(primes.begin(), primes.end(), n)-primes.begin());
  }
  return 0;
}

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

int main()
{
	unsigned int  n;
	cin >> n;
	unsigned  int num,count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(int j = 2; j <=num; j++)
		{
			if(num == j)count++;
			if((num % j) == 0)
			{
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <map>

bool fermat_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
    }
}

bool prime_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
            if ((n %= 2) == 0) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    std::map<int, int> m;
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 2; i <= n; ++i) {
            if (m.count(i) > 0)
                continue;

            m[i] = m[i - 1] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", m[n]);
    }
}

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

const int MAXN = 1e6;

bool is_prime[MAXN];
int prime_count[MAXN];

void init() {
	fill(is_prime, is_prime + MAXN, true);
	int cnt = 0;
	for (int i = 2; i < MAXN; ++i) {
		if (is_prime[i]) {
			++cnt;
			for (int j = i + i; j < MAXN; j += i) {
				is_prime[j] = false;
			}
		}
		prime_count[i] = cnt;
	}
}

int main() {
	//freopen("0009.txt", "r", stdin);
	init();
	int n;
	while (cin >> n) {
		cout << prime_count[n] << "\n";
	}
}

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

int main()
{
	vector<int> prime,count;
	int j, k, x, num;
	while (cin >> num){
		prime.push_back(2);
		x = 1;
		k = 1;
		while (prime[k-1] <= num)
		{
			x += 2;
			j = 0;
			while (j < k && x % prime[j] != 0)j++;
			if (j == k)
			{
				prime.push_back(x);
				k++;
			}
		}
		count.push_back(prime.size() - 1);
		prime.clear();
	}
	for (int i = 0; i < count.size(); i++)
	{
		cout << count[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int isPrime(int n) {
	if (n == 2) {
		return 1;
	}
	if ((n <2) || (n % 2 == 0)) {
		return 0;
	}
	int i = 3;
	while (i <= sqrt(n)) {
		if (n % i == 0) {
			return 0;
			
		}
		i += 2;
	}
	return 1;
}
int main()
{
	int x[30];
	int i = 0;
	while (cin >> x[i]) {
		int k = 0;
		for (int j = 0; j < x[i]; j+=2) {
			
			k += isPrime(j+1);
		}
		cout << k+1 << endl;

		i++;
	}

	return 0;
}