Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <cstdio>
#include <cstring>
#define N 1000000
int n;
bool prime[N];
int num[N];
int main() {
    memset(prime, 1, sizeof prime);
    //for (int i=0;i<N;++i)prime[i]=true;
    prime[1] = prime[0] = num[0] = false;
    for (int i = 2; i < N; ++i)
        if (prime[i]){
            for (int j = 2 * i; j < N; j += i) prime[j] = false;
        //if (i%1000==0)
        //printf("%d %d\n",i,prime[i]);
    }
    for (int i = 1; i < N; ++i) num[i] = prime[i] + num[i-1];
    while (~scanf("%d", &n)) printf("%d\n", num[n]);
    return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main()
{
    int n;
    set<int> prime;
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            bool is_prime = true;
            int tmp = 2;
            for(auto num : prime)
            {
                if(num >= i) break;
                if(i % num == 0)
                {
                    is_prime = false;
                    break;
                }
                tmp = num;
            }
            for(int j = tmp; is_prime && j <= i / 2; j++)
            {
                if(i % j == 0)
                {
                    is_prime = false;
                    break;
                }
            }
            if(is_prime) 
            {
                prime.insert(i);
            }
        }
        int cnt = prime.size();
        for(auto it = prime.rbegin(); it != prime.rend(); it++)
        {
            cerr << *it << ' ';
            if(n < *it) cnt--;
            else break;
        }
        cout << cnt << endl;
    }
}

C++: // AOJ 009

#include <iostream>
#define MAX_NUMBER 50 //1000000
using namespace std;

bool isPrime[MAX_NUMBER];

void SetFalseToMultiples (int prime) {
	for (int i = prime*2; i < MAX_NUMBER;i+=prime) {
		isPrime[i] = false;
	}
	return;
}	

int CountPrimes(int n) {
	int count = 0;
	for (int i = 1;i <= n;i++) {
		if (isPrime[i]) count++;
	}
	return count;
}

int main() {
	for (int i = 0;i < MAX_NUMBER;i++) {
		isPrime[i] = true;	
	}
	isPrime[1] = false;
	
	for (int i = 1;i < MAX_NUMBER;i++) {
		if (isPrime[i]) {
			SetFalseToMultiples(i);
		}
	}
	int n;
	while (cin >> n) {
		cout << CountPrimes(n) << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;

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

int main(){
	int n;
	while(cin>>n){
		int sum=1;
		for(int i=3;i<=n;i+=2){
			if( isPrime(i) )sum++;
		}
		if(n==1)sum=0;
		cout<<sum<<endl;
	}
}

C++: // 2015/05/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[1000000];		// 素数かどうかのテーブル

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<1000000; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<1000000; i++){
		if(is_prime[i]){
			for(int j=i*i; j<1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}

	int n_prime[1000000];		// 素数の個数のテーブル

	int cnt = 0;
	for(int i=0; i<1000000; i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i] = cnt;
	}

	while(true){
		int n;
		cin >> n;

		if(cin.eof())
			break;

		cout << n_prime[n] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
    int n;
    char prime[1000000] = {1, 1};
    for(int k = 2; k < 1000; k++){
        if(prime[k] == 0){
            for(int j = k * k; j < 1000000; j += k)
                prime[j] = 1;
        }
    }
    while(cin >> n){
        int res = 0;
        for(int j = 2; j <= n;j++) 
			if(prime[j] == 0) 
				res++;
        cout << res << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int k, n, s, t, i = 0, j, maxV = INT_MIN, A[30] = {};
	while (cin >> k) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0;
	bool isP = false;
	for (k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			t = (s - 1) / k;
			for (j = 2; j <= t; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}

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

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long int ll;
typedef vector<long long int> vi;
typedef vector<long long int>::iterator vit;

int main(){
	vi v(1000010, 1);
	vi copy(1000011, 1);
	ll n, c = 0;
	double rt;

	v[0] = 0;

	while (cin >> n){
		rt = sqrt(n);
		FOR(i, 1, rt){
			if (v[i] == 1){
				for (int j = i + 1; (i + 1)*j <= n; j++){
					v[(i + 1)*j - 1] = 0;
				}
			}
		}
		/*REP(i,n){
			cout << v[i] << "\n";
		}*/
		REP(i, n){
			if (v[i] == 1)c++;
		}
		cout << c << "\n";
	}
}

C++: #include<stdio.h>
#include<math.h>
int isprime(int x){
	int i=3;
	while( i <= sqrt(x) ){
		if(x%i==0)return 0;
		i = i + 2;
	}
	return 1;
}
int main(){
	int n,c;
	while(scanf("%d",&n)!=EOF){
		c=1;
		for(int i=3;i<=n;i+=2)if(isprime(i))c++;
		printf("%d\n",c);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int n;
#define MAX_N 1000000

int prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数

// n以下の素数の数を返す
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;
}

main() {
    sieve(MAX_N);
    cin>>n;
    int ans=0;
    for(int i=2;i<=n;i++) {
        if(is_prime[i]) ans++;
    }
    cout << ans << endl;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
 
using namespace std;
 
int main(){
    int n;
    int count = 0;
    while(cin >> n){
        count = 0;
        for(int i = 2; i <= n; i++){
            for(int j = 2; j <= i; j++){
                if(i - j > 0) if(i % j == 0) break;
                i - j || i % j || count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

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

const int MAX_N = 999999;
bool prime[MAX_N + 1];

void sieve()
{
  prime[0] = prime[1] = false;
  for(int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  for(int i = 2; i <= MAX_N; ++i)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
}

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n, i;
  int ans = 0;
  sieve();
  while(cin >> n){
    for(i = 0; i < n; i++){
      if(is_prime(i)){
	ans++;
      }
    }
    if(i == n - 1){
      break;
    }
  }
  printf("%d\n", ans);
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[1000000];
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	for(long i=2;i<1000L;i+=1L){
		for(long j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}
	long n;
	while(cin>>n){
		long cnt=0;
		rep(i,n+1){
			if(prime[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}