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 <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

#define MAX_PRIME 1000000

vector<int> primes;
vector<bool> isPrime(MAX_PRIME+1, true);

// sieve of Erastosthenes
inline void prime_list(){
  const int sz = MAX_PRIME;
  isPrime[0]=isPrime[1]=false;
  for(int i=4;i<=sz;i+=2) isPrime[i]=false;
  primes.pb(2);
  for(int i=3; 2*i<=sz; i+=2){
    if(isPrime[i]){
      primes.pb(i);
      for(long j=(long)i*i; j<=sz; j+=i) isPrime[j]=false;
    }
  }
}

int main(){
  prime_list();
  int d;
  while(cin>>d){
    cout << upper_bound(all(primes), d) - primes.begin() << endl;
  }

  return 0;
}

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