Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: #include <iostream>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cctype>
using namespace std;


int n,cnt;
bool is_prime[1000005];

void mk_prime(int n){
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=n;i++) is_prime[i]=true;
    for(int i=2;i*i<=n;i++) if(is_prime[i]){
        for(int j=i*i;j<=n;j+=i){
            is_prime[j]=false;
        }
    }
}

int main(){
    mk_prime(1000005);
    while(cin>>n){
        cnt=0;
        for(int i=2;i<=n;i++){
            if(is_prime[i]) cnt++;
        }
        cout <<cnt<<endl;
    }
    return 0;
}

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

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
	p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num){
	// num???????´???°?????°
	int count = 0;
	
	// Route Num?????´??°??¨??????????????????
	int routeN_int = (int)sqrt(num);
	//cout << routeN_int << endl;
	
	// ???n?????§?????´??°?????????????´???°????????°????????????
	vector<bool> prime_flag_set(num + 1, true);
	
	for(int i = 0; i < prime_flag_set.size(); i++){
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	//cout << endl;
	// 1???2 ?????? n ?????§?????´??°????????????p????????°????????? = false
	for(int p = 2; p < prime_flag_set.size(); p++){
		if( prime_flag_set[p] == false){
			continue;
		}
		int j = 2;
		// 3???2??????????????°?????????????????????p ??? ???n ????¶????????????????
		while(p < routeN_int){
			if(p*j > num+1){
				// num??\???
				break;
			}
			prime_flag_set[p * j] = false;
			//p????????°????±???????
			j++;
		}
	}
	// 2??\???
	for(int i = 2; i < prime_flag_set.size(); i++){
		if(prime_flag_set[i] == true){
			count++;
		};
		//cout << "Flag" << i << " " << prime_flag_set[i] << endl;
	}
	
	return count;
}

int main(){
	int num = 0;
	while(cin >> num){
		cout << SieveOfEratosthenes(num) << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void)
{
	int n;
	while(cin >> n){
		int sosu = 0;
		for(int i = 2; i <= n; i++){
			int count = 0;
			if(i % 2){
				for(int j = 1; j <= i; j++){
					if(i % j == 0) {
						count++;
					}
				}
				if(count == 2) sosu++;
			}
		}cout << sosu+1 << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <bitset>

using namespace std;

int main()
{
  int n;
  bitset<1000000> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i< 1000000; i++) {
    for (int j = i * 2; j < 1000000; j += i) {
      is_prime[j] = false;
    }
  }
  while (scanf(" %d ", &n) == 1) {
    int c = 0;
    for (int i = 0; i <= n; i++) {
      if (is_prime[i]) {c++;}
    }
    printf("%d\n", c);
  }
  return 0;
}

C++: #include <iostream>

int main() {
  int a;

  while(std::cin >> a) {
    bool flag = false;
    int prime = 0;

    for(int cnt = 2; cnt <= a; ++cnt) {
      int fact = 2;
      flag = false;

      while(fact < cnt) {
        if(cnt % fact == 0) {
          flag = true;
          break;
        }
        ++fact;
      }

      if(!flag) {
        ++prime;
      }

    }
    std::cout << prime << std::endl;
  }

}

C++: /*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0009&lang=jp*/

#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin>>n){
        int count=0;
        for (int i = n; 1 < i ; i--) {
            int prime_flag= 1;
            for (int j = i - 1 ; 1 < j ; j--) {
                if(i%j==0){
                    prime_flag= 0;
                }
            }
            count+=prime_flag;
        }
        cout<<count<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool flag[10000001];

int main(){
    int n=0,ans=0;
	for(int i=0;i <= 1000000;i++){
		if(i<=1)flag[i]=false;
		else flag[i]=true;
	}
	for(int i=2;i <= 1001 ;i++){
		if(flag[i]==true){
			for(int j=i*2 ; j<=1000000 ; j=j+i){
				flag[j] = false;
			}
		}
	}
    while(cin>>n){
		ans=0;
		for(int i=0;i <= n;i++){
			if(flag[i]==true){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

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

const int M = 1000010;
int prime[M];
bool isprime[M];

bool is_prime(int n);  
int sieve(int n);  

int main ( )
{
    int n;
    while(~scanf("%d",&n))
        printf("%d\n",sieve(n));

    return 0;
}

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

    return n!=1;
}

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

C++: #include <iostream>
#include <string>
#include <array>
#include <cstdlib>
#include <cmath>

int main() {
	std::array<char, 1000000> is_prime_table = { 0, 0, 1 };
	for( int i=3; i<=is_prime_table.size(); i+=2 ) {
		if ( [&i]() -> bool
		{
			for( int j=3; j<=std::sqrt(i); j+=2 )
				if ( i % j == 0 )
					return false;
			return true;
		}() )
			is_prime_table[i] = 1;
	}
	
	std::string line;
	while( std::getline( std::cin, line ) ) {
		int const num = std::atoi( line.c_str() );
		int result = num > 1 ? 1 : 0;	// 2
		
		for( int i=3; i<=num; i+=2 )
			if ( is_prime_table[i] == 1 )
				++result;

		std::cout << result << std::endl;
	}
}

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n * 1.0); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

C++: #include <bits/stdc++.h>
#define MAX_N 1000000
using namespace std;
bool prime[MAX_N];
int table[MAX_N];

void initialize() {
    int p = 0;
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false;
    for(int r = 2; r * r <= MAX_N; r++) {
        if(prime[r]) {
            table[p++] = r;
            for(int c = r * 2; c <= MAX_N; c+= r) {
                prime[c] = false;
            }
        }
    }
}


int main(void) {
    initialize();
    int num;
    while(cin >> num) {
        int cnt = 0;
        for(int r = 0; table[r] <= num; r++) cnt++;
        cout << cnt << endl;
    }
    return(0);
}