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 <iostream>
using namespace std;

bool f(int n)
{
     bool flag = true;
     for(int j=2; j<n; j++)
     {
         if(n%j == 0)
             flag = false;
     }
     if (flag == true)
         return 1;
     else
         return 0;
}

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

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

vector<char> sieve(const int M){
    vector<char> isPrime(M);
    for(int i=2;i<M;i++) isPrime[i] = true;
    for(int i=2;i*i<M;i++){
        if(not isPrime[i]) continue;
        for(int j=i*i;j<M;j+=i){
            isPrime[j] = false;
        }
    }
    return isPrime;
}

int main (int argc, char const* argv[])
{
    int n;
    vector<char> p;
    while(cin >> n){
        int count = 0;
        p = sieve(n+1);
        for(vector<char>::iterator it = p.begin(); it != p.end() ; ++it){
            if(*it == true)
                ++count;
        }
        
        cout << count << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<utility>
#include<numeric>
#include<iterator>
#include<algorithm>
#include<functional>
#include<ctime>
#include<cassert>
using std::cin;
using std::cout;
using std::endl;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
#define FOR(i,init,len) for(int i=(init);i<(len);++i)
#define For(i,init,len) for(int i=(init);i<=(len);++i)
#define fi first
#define se second
#define pb push_back
#define is insert
namespace IO {
	inline char getchar() {
		static const int BUFSIZE=5201314;
		static char buf[BUFSIZE],*begin,*end;
		if(begin==end) {
			begin=buf;
			end=buf+fread(buf,1,BUFSIZE,stdin);
			if(begin==end) return -1;
		}
		return *begin++;
	}
}
inline void read(int &in) {
	int c,symbol=1;
	while(isspace(c=IO::getchar()));
	if(c=='-') { in=0;symbol=-1; }
	else in=c-'0';
	while(isdigit(c=IO::getchar())) { in*=10;in+=c-'0'; }
	in*=symbol;
}
inline int read() { static int x;read(x);return x; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
#define PA(name,init,len) cout<<#name"["<<(len-init)<<"]=";FOR(_,init,len) cout<<name[_]<<" \n"[_==(len-1)];
#define Pa(name,init,len) cout<<#name"["<<(len-init+1)<<"]=";For(_,init,len) cout<<name[_]<<" \n"[_==(len)];
#define PV(name) cout<<#name"="<<name<<'\n';

const int maxn=1e6+10;
int pr[maxn];
char vis[maxn];
int n;

int main() {


    memset(vis,1,sizeof(vis));
    vis[0]=vis[1]=false;
    For(i,2,maxn) if(vis[i]){
        int j=i*2;
        while(j<=maxn) vis[j]=false,j+=i;
    }
    For(i,2,maxn) pr[i]=pr[i-1]+vis[i];
    while(scanf("%d",&n)==1) printf("%d\n",pr[n]);


	return 0;
}

C++: #include <iostream>
#include <math.h>
 
#define N 1000000
 
using namespace std;
 
int main(){
    bool prm[N];
    for(int i=0;i<N;i++)prm[i]=true;
    int upto = (int)sqrt(N);
    for(int i=2;i<=upto;i++){
        if(prm[i]){
            for(int j=2;i*j<=N;j++) prm[i*j] = false;
        }
    }
    int n;
    while(cin >> n){
        int count = 0;
        for(int i=2;i<=n;i++){
            if(prm[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	while (cin)
	{
		int tmp;

		cin >> tmp;

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		//if (cin.eof()) { break; }
	}

	return 0;
}

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

const int MAX_N = 1000000;

int cnt = 0;
int prime[MAX_N], vis[MAX_N];

void init() {
  memset(vis, 0, sizeof(vis));
  int m = sqrt(MAX_N + 0.5);
  for (int i = 2; i <= m; i++) if (!vis[i]) {
    for (int j = i * i; j <= MAX_N; j += i) {
      vis[j] = 1;
    }
    prime[cnt++] = i;
  }
}

int main() {
  init();
  int n;
  while (scanf("%d", &n) == 1) {
    printf("%ld\n", upper_bound(prime, prime + cnt, n) - prime);
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

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

int main(void)
{
	int n;
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(sosu(i))
				ans++;
		}
		cout<<ans<<endl;
	}
}

C++: #include<stdio.h>
const int MAX_V=10000;
int prime[MAX_V+1];
int main(){
  int i,k,n,p,q,v;
  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;
      }
    }
  }
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(v=2;v<=n-2;v++){
      int isprime=prime[v]*prime[v+2];
      if(isprime)p=v,q=v+2;
    }
    printf("%d %d\n",p,q);
  }
  return 0;
}

C++: #include<stdio.h>

int pr[78498];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
      return nxp;
    }else{
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i,j=0;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF&&j<30){
        /*printf("n=%d\n",n);*/
        i=0;
        if(n-1){
            while(pr[i]<=n){
                /*printf("prime:%d(%d)\n",pr[i],i+1);*/
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
        j++;
    }
}

C++: #include<vector>
#include<algorithm>

std::vector<int> primeNumbers = {2, 3};
std::vector<bool> isPrime;

void eratosthenes(int n){
    int i, j;
    int s = 4;

    isPrime.assign(std::max(n + 1, 2), true);
    isPrime[0] = false;
    isPrime[1] = false;

    for(i = 4 ; i <= n ; i += 2){
        isPrime[i] = false;
    }
    for(i = 9 ; i <= n ; i += 6){
        isPrime[i] = false;
    }

    for(i = 5 ; i * i <= n ; i += s){
        if(isPrime[i]){
            primeNumbers.emplace_back(i);
            for(j = i * i ; j <= n ; j += i){
                isPrime[j] = false;
            }
        }
        s ^= 6;
    }
    for( ; i <= n ; i += s){
        if(isPrime[i]){
            primeNumbers.emplace_back(i);
        }
        s ^= 6;
    }

    return;
}

#include<iostream>

int main(){
    eratosthenes(999999);

    int n;
    while(std::cin >> n){
        std::cout << std::upper_bound(primeNumbers.begin(), primeNumbers.end(), n) - primeNumbers.begin() << std::endl;
    }

    return 0;
}