Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

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

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

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
	int n[30];
	bool po[1000001];
	rep(i,1000001)po[i]=true;
	int prime[1000001]={0};
	po[0]=false;
	po[1]=false;
	int cnt;
	while(cin>>n[cnt]) cnt++;

	int m=0;
	rep(i,cnt) m=max(n[i],m);

	for(int j=2;j<=m;j++){
		if(po[j]){
			prime[j]=prime[j-1]+1;
			for(int k=1;j*k<=m;k++) {
				po[j*k]=false;
			}
		}else{
			prime[j]=prime[j-1];
		}
	}

	rep(i,cnt) cout << prime[n[i]] << endl;

        return 0;
}

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


int main(){
	int number,cnt=0;
	cin>>number;
	int* arr = new int[number+1];
	for (int i = 1; i <= number; i+=2)
	{
		arr[i-1]=0;
		arr[i]=1;
	}
	for (int i = 3; i < sqrt(number); i+=2)
		if (arr[i])
			for (int j = i+i; j <=number; j+=i)
				arr[j]=0;
	arr[2]=1;arr[1]=0;
	for (int i = 0; i <= number; i++)
		if (arr[i])
			++cnt;
	cout<<cnt;
}

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

const int MAX_N = 1000000;

vector<int> init(void){
    vector<int> prime;
    bool is_prime[MAX_N];
    memset(is_prime, true, MAX_N);
    
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<MAX_N; i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i; j<MAX_N; j+=i) is_prime[j] = false;
        }
    }
    return prime;
}

int main(int argc, const char * argv[])
{
    int n;
    vector<int> prime = init();
    while(cin>>n){
        cout << upper_bound(prime.begin(), prime.end(), n)-prime.begin() << endl;
    }
    return 0;
}

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

int main(int, char**)
{
	std::vector<int> nums;
	nums.reserve(30);
	std::vector<bool> pegion;
	pegion.resize(1000000, false);
	pegion[2] = true;

	int buff;
	int max = 0;
	while (std::cin >> buff)
	{
		nums.emplace_back(buff);
		if (max < buff)
		{
			max = buff;
		}
	}

	for (int target = 3; max >= target; ++target)
	{
		if (0 == target % 2)
		{
			continue;
		}
		int count = 0;
		bool flag = true;
		for (count = 3; target >= count * count; ++count)
		{
			if (0 == target % count)
			{
				flag = false;
				break;
			}
		}
		pegion[target] = flag;
	}

	for (const int num : nums)
	{
		int count = 0;
		for (int index = 0; num >= index; ++index)
		{
			if (pegion[index])
			{
				count += 1;
			}
		}
		std::cout << count << std::endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  int n,k;
  vector<int> vi;
  vi.push_back(2);
  for(int i=3;i<=999999;i+=2){
    k=0;
    for(int j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0)vi.push_back(i);
  }	
  while(cin>>n){
    int l;
    for(l=0;vi[l]<=n;l++);
    cout<<l<<endl;
  }
  return 0;
}

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

int main(){
    int n;
    vector<int> S;

    while(cin>>n){
        S.push_back(2);
        int ans=0;
        for(int i=3; i<=n; i+=2){
            int judge=0;
            for(int j=0; j<S.size(); j++){
                if(i%S[j]==0)judge=1;
            }
            if(judge==0){
                ans++;
                S.push_back(i);

            }
        }
        cout<<ans+1<<endl;
        S.clear();
    }
    return 0;
}

C++: #include<cstdio>

using namespace std;
int prim[1000100];
int prima[1000100];

int main() {
    int n, i, x = 0;
    for (i = 2; i <= 1000000; i++) {
        prim[i] = i;
    }
    for (i = 2; i <= 1000000; i++) {
        if (prim[i] != 0) {
                  prima[x] = prim[i];
                  x+= 1;
                  int j = i;
                  while ( j <= 1000000) {
                        prim[j] = 0;
                        j+= i;
                  }
        }
    }
    while (scanf("%ld", &n) != EOF) {
          int a = 0;
          while ( prima[a] <= n) {
                a++;
          }
          printf("%ld\n", a);
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool isPrime[1000006];
int dp[1000006];

int main() {
    rep(i, 1000006) isPrime[i] = true;
    isPrime[0] = isPrime[1] = false;
    rep(i, 1000006) if (isPrime[i]) {
        for (int j = i * 2; j < 1000006; j += i) isPrime[j] = false;
    }
    rep(i, 1000006) if (i) {
        dp[i] = dp[i - 1];
        if (isPrime[i]) dp[i]++;
    }
    int n;
    while (cin >> n) {
        cout << dp[n] << endl;
    }
    return 0;
}

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

typedef unsigned int Int;

Int sqrt_prm(const Int& target, Int x = 0) {
	while (x*x < target) {
		x++;
	}
	return x;
}

int main() {
	while (not std::cin.eof()) {
		Int target;
		std::cin >> target;

		std::vector<Int> primes = {};
		Int sqrt = 1;
		for (Int n = 3; n <= target; n+=2) {
			bool flag = true;

			sqrt = sqrt_prm(n, sqrt);
			for (auto&& div : primes) {
				if (n > sqrt) { break; }
				if (n % div == 0) {
					flag = false;
					break;
				}
			}

			if (flag) {
				primes.push_back(n);
			}
		}

		std::cout << primes.size() << std::endl;
	}
}

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

using namespace std;


int main(int argc, const char * argv[]) {
    // insert code here...
    
    int maxNumber;
    int countPrime=0;
    bool judgePrime = true;
    
    while(cin >> maxNumber){
        for(int i=2; i<=maxNumber;i++){
            for(int j=2; j<i;j++){
                if(i%j==0){
                    judgePrime = false;
                }
            }
            if(judgePrime){countPrime++;}
            judgePrime = true;
        }
        cout << countPrime << endl;
    }
    

    return 0;
}

C++: // AOJ 009

#include <iostream>
#define MAX_NUMBER 1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples (int prime) {
	for (int i = prime*2; i < MAX_NUMBER;i+=prime) {
		isPrime[i] = false;
	}
	return;
}	

int CountPrimes(int n) {
	int count = 0;
	for (int i = 1;i <= n;i++) {
		if (isPrime[i]) count++;
	}
	return count;
}

int main() {
	for (int i = 0;i < MAX_NUMBER;i++) {
		isPrime[i] = true;	
	}
	isPrime[1] = false;
	
	for (int i = 1;i < MAX_NUMBER;i++) {
		if (isPrime[i]) {
			SetFalseToMultiples(i);
		}
	}
	int n;
	while (cin >> n) {
		cout << CountPrimes(n) << endl;
	}
	return 0;
}

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

int a[1000000]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 1000000; i++){
		for(int j = 0; j < 1000000; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		for(int j = 2; j <= n; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}