Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <iostream>
#include <sstream>
#include <fstream>

#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>

#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
        os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

string const resstr[] = {"Impossible","Possible","No","Yes"};

bool p[100010];

void erato(){
	fill(p, p+100010, true);
	p[0] = p[1] = false;
	
	for(int i=0; i < 100010; i++){
		if(!p[i]) continue;
		for(int j=i+i; j < 100010; j+=i){
			p[j] = false;
		}
	}
}

int main(){
	int n;
	erato();
	while(cin >> n){
		int count = 0;
		for(int i=0; i <= n; i++){
			if(p[i]) count++;
		}
		cout << count << endl;
	}
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<bool> prime(1e6, true);
  prime[0] = prime[1] = false;
  for(int i = 2; i * i < 1e6; ++i) {
    if(prime[i]) {
      for(int j = i * i; j < 1e6; j += i) {
        prime[j] = false;
      }
    }
  }

  vector<int> cnt(1e6, 0);
  for(int i = 1; i <= 1e6; ++i) {
    cnt[i] = cnt[i - 1] + prime[i];
  }

  int n;
  while(cin >> n, !cin.eof()) {
    cout << cnt[n] << endl;
  }
}

C++: #include<stdio.h>

int main(void)
{
	int data,i=0,j=2,k=0,l=0,kai[100]={0},s[10000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<0)break;
		else if(data=1)
		{
			kai[k]=0;
		}
		else
		{
			for(i=2;i<data;i++)
				s[i]=i;
		
			for(i=2;i*2<data;i++)		
			{
				for(j=2;j*i<data;j++)				
					s[j*i]=0;
			}
			for(i=2;i<data;i++)
			{	
				if(s[i]!=0)
				{
					l+=1;
				}
			}
		}
		kai[k]=l;
		k+=1;
	}

  for(j=0;j<k;j++)
    printf("%d\n",kai[j]);
  return 0;
}

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

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

using namespace std;

int main()
{
    int n;
    bool prime[1000000];

    prime[0] = false;
    for (int i = 1; i < 1000000; i++) 
        prime[i] = true;

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


    while (cin >> n) {
        int cnt = 0;

        for (int i = 0; i < n; i++)
            if (prime[i] == true)
                cnt++;
        cout << cnt << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstring>
#define MAX 46656
#define LMT 216
#define LEN 4830
#define RNG 100032
#define sq(x) ((x)*(x))
#define mset(x,v) memset(x, v , sizeof(x))
#define chkC(x,n) (x[n >> 6] & (1 << ((n >> 1) & 31)))
#define setC(x,n) (x[n >> 6] |= (1 << ((n >> 1) & 31)))
using namespace std;
unsigned base[MAX/64], segment[RNG/64], primes[LEN];

void sieve()
{
    unsigned i, j, k;
    for (i = 3; i < LMT; i += 2)
    {
        if (!chkC(base, i))
        {
            for (j = i * i, k = i << 1; j < MAX; j += k)
                setC(base, j);
        }
    }
    for (i = 3, j = 0; i < MAX; i += 2)
    {
        if (!chkC(base, i))
            primes[j++] = i;
    }
}

int main()
{
    int n,i,c;
    sieve();
    while(cin>>n)
    {
        if(n==0 || n==1)
        {
            cout<<1<<endl;
            continue;
        }
        c=1;
        for(i=0;i<MAX;i++)
            if(primes[i]<=n) c++;
            else break;
        cout<<c<<endl;
    }
}

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

int main(){
	int n,k,p[100000],s,i,j;
	k=1;
	p[0]=2;
	for(i=3;i<99999;i+=2){
		s=0;
		for(j=0;j<k;j++){
			if((i%p[j])==0){
				s++;
			}
		}
		if(s==0){
			p[k]=i;
			k++;
		}
	}
	
	while(cin >> n){
		if(n<100000){
			for(i=0;n>=p[i];i++){
			}
			cout << i <<"\n";
		}
		else{
			n=n/log(n);
			cout << n <<"\n";
		}
	}
return 0;
}

C++: #include<stdio.h>
#include<math.h>

int main()
{
	int n, i,j,k,cnt;
	while (scanf("%d", &n) != EOF)
	{
		cnt = 0;
		if (n <= 1)
		{
			printf("0\n");
			continue;
		}
		if (n == 2)
		{
			printf("1\n");
			continue;
		}
		if (n <= 4)
		{
			printf("2\n");
			continue;
		}
		for (j = 5; j <= n; j+=2)
		{
			k = 0;
			for (i = 3; i <= sqrt(n*1.0); i += 2)
			{
				if (j%i == 0)
				{
					k = -1;
					break;
				}
			}
			if (k == -1)continue;
			cnt++;
		}
		printf("%d\n", cnt + 2);
	}
}

C++: #include<stdio.h>
#include<math.h>

int main(){
	int n,t;
	while(scanf("%d",&n)!=EOF){
		int c=1;
		for(int i=3;i<=n;i+=2){
			int j=3;
			t=1;
			while( j <= sqrt(i) ){
				if(i%j==0){
					t=0;
				}
				j+=2;
			}
			if(t!=0){
				t=1;
			}
			if(t){
				c++;
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

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

#define Max 1000000

int isPrime[Max];

int main(){
    int num;
    int i,j;

    //配列の初期化
    isPrime[0] = isPrime[1] = 0;
    for(i = 2; i < Max; ++i){
        isPrime[i] = 1;
    }

    for(i = 2; i < Max; i++){
        if(isPrime[i] == 1){
            for(j = 2; i * j <= Max; ++j){
                isPrime[i * j] = 0;
            }
        }
    }

    while(cin >> num){
        int count = 0;
        for(i = 2; i <= num; ++i){
            if(isPrime[i] == 1){
                count++;
            }
        }
        cout << count << endl;
    }
}

C++: /*
Volume0-0009
*/
#include <stdio.h>
#include <stdlib.h>

#define N 999999
#define M (999999/2)
#define TRUE (char)(0==0)
#define FALSE !TRUE
#define BUFLEN 1024

int syserr(char *str)
{
  fputs(str, stderr);
  exit(-1);
}

int main(int argc, char *argv[]){
  char *f;
  if ((f = (char *)malloc(M*sizeof(char)))==NULL)
    syserr((char *)"malloc");

  for (int i=0; i<M; i++){
    f[i] = TRUE;
  }
  for (int i=3; i<N; i+=2) {
    if (f[i/2-1] == TRUE ) {
      for (int j=i+2*i; j<N; j+=2*i){
	f[j/2-1] = FALSE;
      }
    }
  }
  int x = 1;
  for (int i=3; i<N; i+=2) {
    if (f[i/2-1]) {
      x = x + 1;
    }
    f[i/2-1]=x;
  }
  char buf[BUFLEN];
  while (fgets(buf,BUFLEN, stdin) != NULL){
    int n = atoi(buf);
    int m=0;
    if (n==2){
      m = 1;
    } else if (n % 2 == 0) {
      m = f[(n-1)/2 - 1];
    } else {
      m = f[n/2 - 1];
    }

    printf("%d\n", m);
  }

  exit(0);
}