Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

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

#define MAX_SIZE (1000000)

int prime[MAX_SIZE];

int main()
{
	int n;
	
	prime[0] = prime[1] = 0;

	for (int i = 2; i < MAX_SIZE; i++){
		prime[i] = 1;
	}

	// Sieve of Eratosthenes
	for (int i = 2; i * i < MAX_SIZE; i++){
		if (prime[i]){
			for (int j = i * i; j < MAX_SIZE; j += i){
				prime[j] = 0;
			}
		}
	}

	for (int i = 1; i < MAX_SIZE; i++){
		prime[i] += prime[i - 1];
	}

	while (scanf("%d", &n) != EOF){
		printf("%d\n", prime[n]);
	}

	return (0);
}

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

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList;
		std::list<int> primeList;
		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>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n;
	while(cin >> n){
		int counter = 0;
		if(n != 1)counter++;
		for(int i = 3; i <= n; i += 2){
			for(int j = 2; j * j <= i; j++){
				if(i % j == 0)goto divisible;
			}
			counter ++;
			divisible:;
		}
		cout << counter << endl;
	}
}

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

using namespace std;

int isPrime(int a) {
    for (int i = sqrt(a) + 1; i >= 2; i--)
        if (a % i == 0)
            return 0;

    return 1;
}

int main() {

    #if 0
        ifstream cin("34870.in");
    #endif
            cout << "ok" << endl;
    int many[1000000];

    many[1] = 0;
    many[2] = 1;

    int n;
    while (cin >> n) {
        if (n == 1) {
            cout << 0 << endl;
            continue;
        }


        int i = n;
        while (many[i--] == 0);
        for (i += 1; i <= n; i++) {
            many[i] = many[i-1] + isPrime(i);
        }

        cout << many[n] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define MAX_N 1000000

using namespace std;

bool IsPrime[MAX_N];
int NofP[MAX_N];
void q9() {
	memset(IsPrime, 1, sizeof(IsPrime));
	IsPrime[0] = false;
	IsPrime[1] = false;
	for (int i = 0; i < sqrt(MAX_N); i++) {
		if (!IsPrime[i]) continue;
		for (int j = i * 2; j < MAX_N; j += i) {
			IsPrime[j] = false;
		}
	}

	
	NofP[0] = 0;
	for (int i = 1; i < MAX_N; i++) {
		NofP[i] = NofP[i - 1] + IsPrime[i];
	}

	int n;
	for (; cin >> n;) {
		cout << NofP[n] << endl;
	}
}

int main() {
	q9();
	return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <map>
 
inline 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;
    }
}
 
inline 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 %= i) == 0) {
                return false;
            }
        }
    }
    return true;
}

int m[999999];

int main() {
    m[3] = 2;
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 5; i <= n; i += 2) {
            if (m[i] > 0)
                continue;
 
            m[i] = m[i - 2] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", m[n % 2 == 0 ? n - 1 : n]);
    }
}

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

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

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

using namespace std;

typedef long long ll;

int main()
{
	ll n;
	vector<ll> pl;
	back_insert_iterator<vector<ll> > it(pl);
	
	cin>>n;
		//ú»
		pl.clear();
		//nª2ÈºÌÆ«Ì
		if(n < 2){
			cout<<0<<endl;
			return 0;
		}
		//â¿Ìì¬
		*it = 2;
		for(ll i = 3; i <= sqrt((long double)n); i++){
			for(ll t = 0; t < pl.size(); t++){
				if(i % pl[t] == 0) break;
				if(t == pl.size() -1) *it = i;
			}
		}
		//â¿É©¯é
		int L = pl.size();
		for(ll i = sqrt((long double)n) +1; i <= n; i++){
			for(ll t = 0; t < L; t++){
				if(i % pl[t] == 0) break;
				if(t == L -1) *it = i;
			}
		}
		cout<< pl.size() <<endl;
	
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 999999;
bool p[MAX_N+1];
int sum[MAX_N+1];

void make_prime (void )
{
	fill (p, p+MAX_N+1, true );
	memset (sum, 0, sizeof (sum ) );
	p[0] = false;
	p[1] = false;
	for (int i = 2; i <= MAX_N; i++ ){
		if (p[i] ){
			for (int j = 2*i; j <= MAX_N; j += i ){
				p[j] = false;
			} // end for
		} // end if
	} // end for

	for (int i = 1; i <= MAX_N; i++ ){
		sum[i] = sum[i-1] + (p[i] ? 1 : 0 );
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.PN", "r", stdin );
	make_prime ();

	int n;
	scanf ("%d", &n );
	printf ("%d\n", sum[n] );

	return 0;
}

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

using namespace std;

bool num[1000000] = { false };

void primNumberCheck(){
    num[2] = true;//?\???°?????????????????????????????????2???????????§???????????????

    int i, j, k;
    for (i = 3; i <= 1000000; i += 2)//2????????°???????????????
    {
        k = 0;
        for (j = 3; j <= sqrt((double)i); j += 2)//?????????i??\??????i????´???°??????????????\??????i????´???°??¨?????????????????§????????????
        {
            if (i%j == 0)
            {
                k = 1;
                break;
            }
        }
        if (k == 0)
        {
            num[i] = true;
        }
    }
}

int main()
{
    primNumberCheck();

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

    return 0;
}