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>                                                                                                       
#include <vector>                                                                                                         
#include <list>                                                                                                           
                                                                                                                          
#define MAX 1000000                                                                                                       
                                                                                                                          
using namespace std;                                                                                                      
                                                                                                                          
int main() {                                                                                                              
  vector<int> prime_numbers;                                                                                              
  prime_numbers.push_back(2);                                                                                             
  prime_numbers.push_back(3);                                                                                             
  prime_numbers.push_back(5);                                                                                             
  prime_numbers.push_back(7);                                                                                             
                                                                                                                          
  list<int> search_list;                                                                                                  
  for (int i = 5; i < MAX; i++) {                                                                                         
    if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0) {                                                           
      search_list.push_back(i);                                                                                           
    }                                                                                                                     
  }                                                                                                                       
  int h = search_list.front();                                                                                            
  while (h * h < search_list.back()) {                                                                                    
    prime_numbers.push_back(h);                                                                                           
    list<int>::iterator itr = search_list.begin();                                                                        
    while (itr != search_list.end()) {                                                                                    
      if (*itr % h == 0) {                                                                                                
        itr = search_list.erase(itr);                                                                                     
      } else {                                                                                                            
        itr++;                                                                                                            
      }                                                                                                                   
    }                                                                                                                     
    h = search_list.front();                                                                                              
  }                                                                                                                       
  for (list<int>::iterator itr = search_list.begin(); itr != search_list.end(); itr++) {                                  
    prime_numbers.push_back(*itr);                                                                                        
  }                                                                                                                       
                                                                                                                          
  int n;                                                                                                                  
  while (cin >> n) {                                                                                                      
    int count = 0;                                                                                                        
    for (vector<int>::iterator itr = prime_numbers.begin(); itr != prime_numbers.end(); itr++) {                          
      if (*itr >= n) break;                                                                                               
      count++;                                                                                                            
    }                                                                                                                     
    cout << count << endl;                                                                                                
  }                                                                                                                       
                                                                                                                          
  return 0;                                                                                                               
}

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

int main(){
	int n;
	while(cin >> n){
		bool* p = new bool[n+1];
		int cou = 0;
		for(int i = 0; i < n+1; ++i){
			p[i] = true;
		}
		p[0] = false; p[1] =false;
		for(int i = 2; i*i <= n; ++i){
			for(int j = 2;i*j <= n ; ++j) {
				p[i*j] = false;
			}
		}

		for(int i = 0; i < n+1; ++i ){
			if(p[i] == true) ++cou;
		}
		cout << cou << endl;
	}
    return 0;
}

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

using namespace std;


// cin >>
// cin <<
bool isPrime(int x){
	if(x==2) return true;
	if(x<2||x%2==0) return false;
	int i=3;
	while(i<=sqrt(x)){
		 if (x%i==0)return false;
		i= i+2;
	}
	return true;
}
int main(){
	int in[30]={};
	int out=0;
	for(int i=0;i<30;i++) cin >>in[i];
	for(int i=0;i<30;i++){
		if(in[i]==0){
			break;
		}else{
			out=0;
			for(int j=0;j<in[i]+1;j++){
				if(isPrime(j)==true){
					out++;
				}
			}
			cout <<out<<endl;
		}
	}
	
	return 0;
}