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 := 2; j < i-1; j++ {
				if i%j == 0 && j != 1 {
					flag = true
					//fmt.Println(i, "/", j)
					break
				}
			}
			if !flag {
				count++
			} else {
				flag = false
			}
		}
		fmt.Println(count)
	}
}

C++: #include <cstdio>
#include <vector>
#include <ctime>
 
using namespace std;
 
int main()
{
    int n;
    vector<int> prime;
     
    //unsigned long t = time(NULL);
    prime.push_back(2);
	prime.push_back(3);
    while (scanf("%d", &n) != EOF){
		if (prime[prime.size() - 1] <= n){
			for (int i = prime[prime.size() - 1] + 2; i <= n; i += 2){
				bool p = true;
				for (int j = 0; prime[j] <= i / 2; j++){
					if (i % prime[j] == 0){
						p = false;
						break;
					}
				}
				if (p){
					prime.push_back(i);
				}
			}
		}
		
		int count;
		for (count = 0; count < prime.size() && prime[count] <= n; count++){
			;
		}
		printf("%d\n", count);
    }
     
    return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[30];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num <3; data_num++)
	{
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0)
			break;
	}

	for (k = 0; k < data_num; k++)
	{

		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);

		prime[0] = 0;
		for (i = 1; i < data[k]; i++)
		{
			prime[i] = 1;
		}

		for (i = 1; i < sq_num; i++)
		{

			if (prime[i] == i)
			{
				for (j = (i + 1); (i + 1)* j <= data[k]; j++)
				{
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0; 
		for (i = 0; i < data[k]; i++)
		{
			if (prime[i] == 1)
			{
				cnt++;
			}
		}
		printf("%d\n", cnt);
		free(prime);
	}

	return 0;
}

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

int main() {
	int n;

	while (cin >> n) {
		int count = 0;
		bool table[n + 1] = { false };
		int upper = sqrt(n);

		table[1] = true;

		for (int i = 1; i <= upper; i++) {
			if (table[i] == false) {
				table[i] = true;
				count++;
				for (int j = i; j <= n; j++) {
					if (j % i == 0) {
						table[j] = true;
					}
				}
			}
		}

		for (int i = 1; i <= n; i++) {
			if (table[i] == false) {
				count++;
			}
		}

		cout << count << '\n';
	}

	return 0;
}

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

using namespace std;

#define MAX_N 99999
#define MAX_D 30

bool prime_check(int n, int k = 2)
{
	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	int n;

	bool isprime[MAX_N + 1];

	for (int i = 2; i < MAX_N + 1; i++)
	{
		isprime[i] = prime_check(i);
	}

	while (cin >> n)
	{
		cout << count(isprime + 2, isprime + n + 1, true) << endl;
	}

	return 0;
}

C++: // BCC
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

// GCC
// #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define each(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int INF = 1 << 28;
const ll INFLL = 1ll << 56;


/**
 * ??¨????????????????????????
 * ?´???°??¨??¨?´???°?????????????????????
 */

const int SIEVE_SIZE = 1000000;

bool is_prime[SIEVE_SIZE];
vector<int> primes;

void eratosthenes()
{
	primes.clear();
	for (int i = 2; i < SIEVE_SIZE; i++) is_prime[i] = true;
	
	for (int i = 2; i * i < SIEVE_SIZE; i++){
		if (!is_prime[i]) continue;
		for (int j = i * i; j < SIEVE_SIZE; j += i){
			is_prime[j] = false;
		}
	}
	
	for (int i = 2; i < SIEVE_SIZE; i++){
		if (is_prime[i]) primes.pb(i);
	}
}

int sum[1000000];

int main()
{
	eratosthenes();
	each(p, primes) sum[*p]++;
	rep(i, 999999) sum[i + 1] += sum[i];
	
	int n;
	while (~scanf("%d", &n)){
		printf("%d\n", sum[n]);
	}
}

C++: #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=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>
#include <algorithm>
#include <string>
#include <stdio.h>
using namespace std;
int isprime(int x){
    if(x==2||x==3) return true;
    if(x<5||x%2==0||x%3==0) return false;
    else{
        int i=5;
        while(i<=sqrt(x)){
            if(x%i==0) return false;
            i = i+2;
        }
        return true;
    }
}
int main() {
    int n;
    while(cin >> n){
        int ans=0;
    for (int j=n; j>1; j--) {
        if(isprime(j)!=0) ans++;
    }
    cout << ans << endl;
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool era[10000000]={false};
 
 
void makeERA(){
    for(int i=2;i<1000001;i++){
        if(era[i]!=true)continue;
        for(int j=2;;j++){
            if(i*j<=1000000)
                era[i*j]=false;
            else break;
        }
    }
    era[2]=true;
}
int main(){
    rep(i,10000000)era[i]=true;
    era[0]=false;era[1]=false;
	makeERA();
	int n;
	while(cin>>n){
		if(n==0)break;

		int sum=0;

		rep(i,n+1){
			if(era[i])sum++;
		}
		cout<<sum<<endl;
	}
}

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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {
    int n; // 10000
    scanf("%d", &n);

    int cnt = 0;
    REP(2, i, n) {
        if (isPrime(i)) cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	vector<int> v;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		v.push_back(n);
	}
	for(int i = 0; i < v.size(); i++){
		for(int j = 2; j <= v[i]; j++){
			if(a[j]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}