Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include <iostream>                                                                                                     
#include <vector>                                                                                                       
                                                                                                                        
using namespace std;                                                                                                    
                                                                                                                        
int main() {                                                                                                            
  int n;                                                                                                                
  cin >> n;                                                                                                             
                                                                                                                        
  if (n == 1) { cout << 0 << endl; return 0; }                                                                          
  if (n == 2) { cout << 1 << endl; return 0; }                                                                          
                                                                                                                        
  vector<int> prime_numbers; // 素数リスト                                                                              
  int c = 1;                                                                                                            
  prime_numbers.push_back(2);                                                                                           
  for (int i = 3; 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);                                                                                       
      c += 1;                                                                                                           
    }                                                                                                                   
  }                                                                                                                     
  cout << c << endl;                                                                                                    
  return 0;                                                                                                             
}

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

const int max_n = 1000000;
int prime[max_n];
bool is_prime[max_n+1];

int sieve(int n)
{
	int p = 0;
	for(int i=0;i<=n;i++){
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j=2*i;j<=n;j+=i)
				is_prime[j] = false;
		}
	}
	return p;
}

int main()
{
	int n;
	cin >> n;
	cout << sieve(n) << endl;
	return 0;
}

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

int main(){
	int m=0,n;
	cin>>n;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define L(_i,_N) for(int _i=0;_i<_N;_i++)
#define C(_Dis) cout<<_Dis<<endl;

using namespace std;

typedef long long int lli;

int main() {
	int n,Count=0;
	while (cin >> n) {
		vector<bool> ch(n+1);
 		for (int i = 2; i <= n; i++) ch[i] = true;
		for (int i = 2; i <= n; i++) {
			if (ch[i]) Count++;
			for (int j = i * 2; j <= n; j += i) ch[j] = false;
		}
		C(Count);
		Count = 0;
	}
	return 0;
}

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

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
int res;
scanf("%d",&n);
for(int i=2;i<=n;i++){
if(is_prime(n)) res = i;
}
printf("%d\n",res);
}

C++: #include <stdio.h>

int isPrime(int n);

int main(void){
    int n;
    int cnt;

    while (scanf("%d", &n)!= EOF){
        cnt = 0;
        for(int i=2; i<=n; i++){
            if (isPrime(i)) cnt++;
        }
        printf("%d\n", cnt);
    }

    return 0;
}


int isPrime(int n){
    int i;
    
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int prime(int n){
	int prime;
	if(n==2) prime=1;
	else if(n==3){
		prime=2;
	}
	else{
		prime=2;
		for(int i=5;i<=n;){
			int m=sqrt((double)i);
			for(int j=3;j<=m+1;j++){
				if(i%j==0) break;
				else{
					if(j==m+1) prime++;
				}
			}
			i += 2;
		}
	}
	return prime;
}

int main(){
	int n;
	while(cin>>n){
		cout<<prime(n)<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int n;
	while (std::cin >> n)
	{
		std::vector<bool> v(n + 1 ,false);
		int c = 0;
		v[0] = true, v[1] = true;
		for (int i = 2; i * i <= n ; ++i) {
			if (!v[i]) {
				for (int j = i * i; j <= n; j += i) {
					v[j] = true;
					++c;
				}
			}
		}

		std::cout << n-c-1 << std::endl;
	}
}

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

int main(){
	int n;
	int *prime,i,j;
	prime = new int[80000];
	int *answer = new int[MAX];
	int count;
	bool flag;

	count = 0;
	answer[0] = 0;
	answer[1] = 0;
	answer[2] = 1;
	for(i = 3; i <= 1000000; i+=2){
		flag = true;
		for(j = 0; j < count; j++){
			if(i % prime[j] == 0){
				flag = false;
				break;
			}
			if(prime[j] * prime[j] > i) break;
		}
		if(flag == true){
			prime[count++] = i;
		}
		answer[i] = count;
		answer[i+1] = count;
	}
	while((cin >> n)!= NULL){
		cout << answer[n] << endl;
	}
	return 0;
}