Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

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

C++: #include <iostream>                                                                                                     
#include <vector>                                                                                                       
                                                                                                                        
using namespace std;                                                                                                    
                                                                                                                        
int main() {                                                                                                            
  int n;                                                                                                                
  int count;                                                                                                            
  while (cin >> n) {                                                                                                    
    if (n == 1) { cout << 0 << endl; continue; }                                                                        
    vector<int> prime_numbers; // 素数リスト                                                                            
    count = 1;                                                                                                          
    for (int i = 2; i <= n; i++) {                                                                                      
      bool prime = true;                                                                                                
      for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) {                      
        if (i % *itr == 0) {                                                                                            
          prime = false;                                                                                                
          break;                                                                                                        
        }                                                                                                               
      }                                                                                                                 
      if (prime) {                                                                                                      
        prime_numbers.push_back(i);                                                                                     
        count += 1;                                                                                                     
      }                                                                                                                 
    }                                                                                                                   
    cout << count << endl;                                                                                              
  }                                                                                                                     
  return 0;                                                                                                             
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int vis[1000000];
int n;int sum;
void pre()
{
    memset(vis, 0, sizeof(vis));
for(int i = 2; i <= 999999; i++)
	for(int j = i*2; j <= 999999; j += i)
		vis[j] = 1;
}
int main()
{
    pre();
    while(scanf("%d",&n)!=EOF)
    {
        sum=0;
        for(int i=2;i<=n;i++)
        {
            if(!vis[i])
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

int primes[78498], num_primes;
int calculated;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	calculated = 2;
	num_primes = 1;
	while (true) {
		int n;
		if (!scanf("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				int max = (int)(sqrt(i)) + 1;
				for (int j=1; primes[j] < max&&j<num_primes; j++) {
					if (i%primes[j] == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

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

const int N = 100000

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N+1)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

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

#define MAX_N 2000000
int prime[MAX_N];



int main(){
	prime[1] = 1;
	prime[2] = 0;
	prime[3] = 0;
	for(int i = 2; i<=MAX_N;i++){
		if(prime[i] == 0)
			for(int j=2*i;j<=MAX_N;j=j+i)
				prime[j] = 1;
	}
	
	int n;
	int num=0;
	while(true){
		cin >> n;
		if (cin.eof() ==1)
			break;	
		for(int k = 1;k<=n; k++){
			if(prime[k]==0)
				num++;
		}
		cout << num << endl;
		num = 0;
	}
	return 0;
}

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

int main(){
	int n,count;
	bool num[1000000];
	while( scanf("%d",&n) != EOF ){
		for(int i=2;i<=n;i++){
			num[i]=true;
		}
		count = 0;
		for(int i=2;i<=sqrt(n);i++){
			if(num[i]){
				for(int j=i;j<=n;j+=i){
					num[j]=false;
				}
				 count++;
			}
		}
		for(int i=2;i<=n;i++){
			count += num[i];
		}
		printf("%d\n",count);
	}
	return 0;
}

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

const int LIMIT = 1000000;

void eratosthenes(int n, bool *primes);

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    bool primes[LIMIT];
    for (int i = 1; i < LIMIT; ++i)
        primes[i] = false;
    eratosthenes(LIMIT, primes);
    int num_of_primes[LIMIT] = {};
    for (int i = 1; i < LIMIT; ++i) {
        num_of_primes[i] = num_of_primes[i-1];
        if (primes[i])
            ++num_of_primes[i];
    }

    int n;
    while (std::cin >> n) {
        std::cout << num_of_primes[n] << std::endl;
    }
}

void eratosthenes(int n, bool *primes)
{
    primes[2] = true;
    int i = 3;
    double root_n = std::sqrt((double) n);
    while (i <= root_n) {
        if (n % i != 0) primes[i] = true;
        i += 2;
    }
}