Go: package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		flag := false
		count := 0

		for i := 2; i <= num; i++ { //1を除く入力値以下の数字
			for j := i - 1; j >= 1; j-- {
				if i%j == 0 && j != 1 {
					flag = true
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

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

using namespace std;

long* primes(long high)
{
  long* p = new long[high];
  for (int i = 0; i < high; i++) {
    p[i] = 0;
  }

  long max = ceil(sqrt(high));
  for (int i = 2; i <= max; i++) {
    if (p[i - 1] == -1) continue;

    int count = 2;
    while (i * count <= high) {
      p[i * count - 1] = -1;
      count++;
    }
  }

  for (int i = 1; i < high; i++) {
    if (p[i] == -1) {
      p[i] = p[i - 1];
    } else {
      p[i] = p[i - 1] + 1;
    }
  }
  
  return p;
}

int main(int argc, char const* argv[])
{
  long* p = primes(999999);
  long n;

  while (cin >> n) {
    cout << p[n - 1] << endl;
  }
  return 0;
}

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

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

bool IsPrimeNumber(long long 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(long long 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(long long i = 0; PrimeNum[i] * PrimeNum[i] <= x; i++)
		if(x%PrimeNum[i] == 0)return false;
	return true;
}


int main(){
	clock_t start, end;
	long long 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 <math.h>
using namespace std;

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        j=past/i; j++;
        chk[j*i]=false;
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

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

//??¨??????????????????????????§?´???°??¨?????????
//?´???°??¨??¨?´???????????????£?????????????????§??¨????????????

const int MAX_V = 999999;
int prime[MAX_V + 1]; //?´???°??¨
int sum[MAX_V + 1]; //?´???°?????°???????¨?

int main()
{
	int i, k, v;
	prime[0] = prime[1] = 0;
	for (i = 2; i <= MAX_V; i++)
	{
		prime[i] = 1;
	}
	for (i = 2; i*i <= MAX_V; i++)
	{
		if (prime[i])
		{
			for (k = 2 * i; k <= MAX_V; k += i)
			{
				prime[k] = 0;
			}
		}
	}

	sum[0] = 0;
	for (i = 0; i < MAX_V + 1; i++)
	{
		sum[i+1] = sum[i] + prime[i+1];
	}

	int input;
	while (cin >> input)
	{
		cout << sum[input] << endl;
	}

	return 0;
}

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

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

int syserr(char *str)
{
  fputs(str, stderr);
  exit(-1);
}
int main(int argc, char *argv[]){
  int *f;
  if ((f = (int *)malloc(M*sizeof(int)))==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==1){
      m = 0;
    } else if (n==2) {
      m = 1;
    } else if (n % 2 == 0) {
      m = f[(n-1)/2 - 1];
    } else {
      m = f[n/2 - 1];
    }

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

  exit(0);
}

C++: #include<iostream>
using namespace std;
int a[1000000]={0};
int main(){
    int n,c=0;
    for(int i=2;i<10000;i++)
        for(int j=i;j*i<1000000;j++)
            a[i*j]=1;
    while(cin>>n){
        c=0;
        for(int i=2;i<=n;i++)
            if(a[i]==0)
                c++;
        cout<<c<<endl;
    }
}

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

int main(void){
int unti[100002] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100001;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100001;a++)
{
	if((a * n  ) < 100001 ) unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}

}

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

// Defines
#define     MAX_NUMBER     (999999)
#define     MIN_NUMBER     (1)
// #define     __DEBUG__

// Using Namespace
using namespace std;

// Function
int main(){
	vector <int> PrimeNumbers;
	vector <int> input;
	int buf;
	int sz,maxn;
	int i,root;

	// 入力
	while(cin >> buf){
		// 入力値のチェック
		if((buf <= ((int)(MIN_NUMBER))) || (buf > ((int)(MAX_NUMBER)))){
			cerr << "InputError!!" << endl;
			cerr << "The number has to more than " << ((int)(MIN_NUMBER));
			cerr << " and less than " << (((int)(MAX_NUMBER)) + 1) << "." << endl;
		}else{
			// 問題がなければ入力値をリストに追加
			input.push_back(buf);
		}
	}

	// n の最大値を求めて maxn に代入
	sz = (int)input.size();
	maxn = input[0];
	for(i=1;i<sz;i++){
		if(maxn < input[i]){
			maxn = input[i];
		}
	}

	// 素数2 を 素数表PrimeNumbers に追加
	PrimeNumbers.push_back(2);

	// 3 から maxn までの整数が素数かどうかを調べ、素数であれば 素数表PrimeNumbers に追加
	for(i=3;i<=maxn;i+=2){
		// root に i の平方根を代入
		root = (int)sqrt(i);
		// sz に 素数表PrimeNumbers の大きさを代入
		sz = (int)PrimeNumbers.size();
		// i が 素数表PrimeNumbers に含まれている素数で割り切れないかを確認
		for(buf=0;(buf < sz) && (PrimeNumbers[buf] <= root);buf++){
			if((i % PrimeNumbers[buf]) == 0){						// もし割り切れたら
				goto NotPrime;										// i を素数表に追加しない
			}
		}
		// i は素数である ならば i を 素数表PrimeNumbers に追加
		PrimeNumbers.push_back(i);
		// ここにジャンプする
		NotPrime:;
	}

	// n 以下の素数の個数を計測
	sz = (int)input.size();
	for(i=0;i<sz;i++){
		// a, b および flag の宣言・初期化
		int a = 0,b = (int)PrimeNumbers.size() - 1,m,n;
		bool flag = false;

		// PrimeNumbers の最大値 <= input[i] となっていないかどうかを調べる
		if(PrimeNumbers[b] <= input[i]){
			n = b;
			flag = true;
		}

		// 二分検索
		while (flag == false){
			m = (a + b) / 2;
			if(PrimeNumbers[m] > input[i]){
				b = m;
			}else if((PrimeNumbers[m] <= input[i]) && (PrimeNumbers[m+1] > input[i])){
				n = m;
				flag = true;
			}else if(PrimeNumbers[m] < input[i]){
				a = m;
			}else{
				cerr << "BinarySearchError!!" << endl << endl;
				cerr << "PrimeNumbers[" << m << "] = " << PrimeNumbers[m] << endl;
				cerr << "PrimeNumbers[" << (m + 1) << "] = " << PrimeNumbers[m+1] << endl;
				cerr << "input[" << i << "] = " << input[i] << endl;
				return -1;
			}
		}

		// 出力
		cout << (n + 1) << endl;
	}

	return 0;
}