Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

#define maxPN 100000
#define PNs  1000100
int countPN = 0, countPNs = 0;
int PrimeNum[maxPN], temp;
bool PN[PNs];

bool IsPrimeNumber(int x);

void PrimeN(){
	int i, j;
	PrimeNum[0] = 2;
	PN[2] = true;PrimeNum[countPN++] = 2;
	PN[3] = true;PrimeNum[countPN++] = 3;
//	PN[5] = true;PrimeNum[countPN++] = 5;
	
	for(i = 6; i  < PNs;i+=6){
		if(IsPrimeNumber(i-1)){
			PrimeNum[countPN++] = i-1;
			PN[i-1] = true;//cout<<i-1<<endl;
		}
		if(IsPrimeNumber(i+1)){
			PrimeNum[countPN++] = i+1;
			PN[i+1] = true;//cout<<i+1<<endl;
		}
		countPNs = i+1;//cout<<i-1<<" "<<PN[i-1]<<endl;
	}
}

bool IsPrimeNumber(int x){
	//if(x == 2 || x == 3) return true;
	//if(x <= 4 || x%2 == 0 || x%3 == 0)   return false;
	//if(x < countPNs) return PN[x];
	for(int i = 0; PrimeNum[i] * PrimeNum[i] <= x; i++)
		if(x%PrimeNum[i] == 0)return false;
	return true;
}


int main(){
//	clock_t start, end;
	int n = true, counta;
//	start = clock();
	PrimeN();
//	cout<<PrimeNum[countPN-1]<<" "<<countPNs<<endl;
//	cout<<clock()-start<<"ms"<<endl;
	
	while(cin>>n){
		counta = 1;
		
		
		//cout<<(IsPrimeNumber(n)?"yes":"no")<<endl;
	//	start = clock();
		//cout<<IsPrimeNumber(n)<<endl;
		for(int i = 1; i <= n; i+=2){
			if(PN[i])counta++;
		//	cout<<i<<" "<<PN[i]<<endl;
		}
		if(n == 1) counta = 0;
		cout<<counta<<endl;
	//	cout<<clock()-start<<"ms"<<endl;
	}
	return 0;
}

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


int main()
{

	int i,n,count;
	deque<int> sosu;
	while(cin >> n){
		if( n <= 2 ) {
			if( n == 2 ) {
				count = 1;
			}
			else 
				count = 0;
		}
		else {
			sosu.push_back(2);
			deque<int>::iterator it;
			bool flg;
			for( i = 3; i <= n ; i+=2 ) {
				flg = false;	
				for(it = sosu.begin(); it != sosu.end(); it++ ) {
					if( i < 2 * (*it) ){
						flg = true;
						break;
					}
					if( i % *it == 0 )
						break;
				}				
				if( flg == true ) {
					sosu.push_back( i );
				}
			}							
			count = sosu.size();
		}
		cout << count << endl;
	}
			
	return 0;
}

C++: #include <iostream>
using namespace std;
int solve(int n){
    int ans,sum=0;
    if(n==1)ans=0;
    else{
        for(int i=1;i<n+1;i++){
            if(n%i==0)sum++;
        }
        if(sum==2)ans=solve(n-1)+1;
        else ans=solve(n-1);
    }
    return ans;
}
int main(void){
    int n;
    while(cin>>n){
        cout<<solve(n)<<endl;
    }
    return 0;
}

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

using namespace std;

vector<int> ary;
const int MAX = 999999;

void generate_prime(int max) {
	bool prime[MAX];

	for(int i = 0; i < max; i++) {
		prime[i] = true;
	}
	prime[0] = false; // 1 is not a prime number

	for(int i = 1; i < sqrt((double)max); i++) {
		if(prime[i]) {
			for(int j = i + 1; (i + 1) * j <= max; j++) {
				prime[(i + 1) * j - 1] = false;
			}
		}
	}

	for(int i = 0; i < max; i++) {
		if(prime[i]) {
			ary.push_back( i + 1 );
		}
	}
}

int main(){
	int n;
	generate_prime(MAX);

	while(cin >> n) {
		vector<int>::iterator it = ary.begin(); 
		int result = 0;

		while(it != ary.end() && *it <= n ) {
			it++;               
			result++;
		}
		cout << result << endl;
	}

	return 0;
}

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

void sieve(int n, list<int> &primes)
{
    vector<bool> v(n / 2 + 1, true);

    // check
    for (int i = 3, end = sqrt(n); i <= end; i += 2) {
        if (!v[i / 2])
            continue;
        for (int j = i * i / 2; j <= n / 2; j += i)
            v[j] = false;
    }

    primes.push_back(2);
    for (int i = 1; i <= n / 2; i++)
         if (v[i])
            primes.push_back(i * 2 + 1);
}

int main()
{
    list<int> primes;
    vector<int> inputs;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        int count = 0;
        for (auto p : primes) // find
            if (p == x) {
                count++;
                break;
            } else if (p > x)
                break;
            else
                count++;
        cout << count << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 999999;
bool p[MAX_N+1];
int sum[MAX_N+1];

void make_prime (void )
{
	fill (p, p+MAX_N+1, true );
	memset (sum, 0, sizeof (sum ) );
	p[0] = false;
	p[1] = false;
	for (int i = 2; i <= MAX_N; i++ ){
		if (p[i] ){
			for (int j = 2*i; j <= MAX_N; j += i ){
				p[j] = false;
			} // end for
		} // end if
	} // end for

	for (int i = 1; i <= MAX_N; i++ ){
		sum[i] = sum[i-1] + (p[i] ? 1 : 0 );
	} // end for
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.PN", "r", stdin );
	make_prime ();

	string str = "";
	while (getline (cin, str ) ){
		stringstream ss (str );
		int n;
		ss >> n;
		printf ("%d\n", sum[n] );
	} // end while

	return 0;
}

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

bool p[1000000];

int main(){
	int c,n;
	while(cin >> n){
		c = 0;
		for(int i = 2; i <= sqrt(n); i++){
			for(int j = 2; i * j <= n; j++){
				p[i*j] = true;
			}
			
		}
		for(int i = 2; i <= n; i++){
			if(p[i] == 0){
				c++;
				
			}
		}
		cout << c << endl;
	}
	
	return 0;
}