Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

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

/** Problem0009 : Prime Number **/
#define MAX 1000000

int main()
{
	bool prime[MAX];
	int  input, count;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin >> input) {
		count = 0;
		for (int i=0; i<=input; i++) {
			if (prime[i]) count++;
		}
		cout << count << endl;
	}
}

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;
	}
}