Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

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
}

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

int main (void){
	int number, i, j, count=0;
	
	while(scanf("%d", &number)!=EOF){
	count=0;
	int n[number];
	for(i=0; i<number; i++){
		n[i]=i;
	}
	
	for(i=0; i<number; i++){
		j=i;
		while(1){
			j+=i;
			if(j>number){break;}
			n[j]=-1;
			if(i==0 || i==1){
				n[i]=-1;
				break;
			}
		}
	}
	
	for(i=0; i<number; i++){
		if(n[i]!=-1){
			//printf("%d\n", n[i]);
			count++;
		}
	}
	printf("%d\n", count+1);
	}
	
	return 0;
}

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++;
    }
}