Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [31]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 <iostream>
#include <cmath>

using namespace std;

    int g(int n){
        int p = 0;
        bool is_prime[n + 1];
        is_prime[0] = is_prime[1] = false;

        for(int i = 2 ; i <= n ; i++)
            is_prime[i] = true;

        for(int i = 2 ; i <= n ; i++){
            if(is_prime[i]){
                p++;
                for(int j = i * 2 ; j <= n ; j += i) // j = i * 2 like 2 started form 4 then add 2 each time j += i not j * 2
                    is_prime[j] = false;
            }
        }
    return p;
}

int main(){
    int n;

    while(cin >> n){
        cout << g(n) << endl;
    }

}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;
	bool prime[1000000] = false;
	prime[1] = true; //1???????????\
	
	while(cin >> n){
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

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

int main(){
	int n;
	while(cin >> n && n<1000000) {
		int s = 0;
			for (int j = 2;j <= n;j++){
				int yaku = 0;
				for (int m = 1;m <= j;m++){
					if (j % m == 0) yaku++;
				}
				if (yaku == 2) s++;
			}
			cout << s << endl;
	}
    return 0;
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(int i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(int i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF 1e10;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define IfOut(condition,text) if((condition)){out(text);return 0;}
#define IfeOut(condition,itext,etext) if(condition){out(itext);return 0;}else{out(etext);return 0;}
#define Select(collection,condition,result) Foreach(i,collection){result+=condition;}
#define GetAuto(_N,vect) {cin>>N;vect.resize(N);REP(i,_N){cin>>vect[i];}}
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
#define beginend(vec) (vec).begin(),(vec).end()
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}


int main() {
	ll n;
	vector<ll> ans;
	while (cin >> n)
	{
		if (n == 1) {
			ans.push_back(0);
			continue;
		}
		int prime;
		double sqrtmax = sqrt(n);
		vector<ll> primeVec, searchVec;
		FOR(i, 2, n + 1) searchVec.push_back(i);
		do
		{
			prime = searchVec[0];
			primeVec.push_back(prime);
			auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });
			searchVec.erase(itr, searchVec.end());
		} while (prime < sqrtmax);
		ans.push_back(primeVec.size() + searchVec.size());
	}
	Foreach(i, ans) out(i);
	return 0;
}

C++: #include <iostream>

int main() {
	int n;
	while (std::cin >> n) {
		int c = 0;
		for (int i = 2; i <= n; i++) {
			bool fg = true;
			for (int j = 2; j < i; j++)
				if (!(i % j))
					fg = false;
			if (fg)
				c++;
		}
		std::cout << c << std::endl;
	}
}

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

int prime[MAX_N];
bool is_prime[MAX_N+1];

int sieve(int n) {
  int p = 0;
  for(int i=0;i<=n;i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i <= n;i++) {
    if(is_prime[i]) {
      prime[p++] = i;
      for(int j=2 * i;j<= n;j += i) is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int n;
  cin >> n;
  cout << sieve(n) << endl;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cmath>

using namespace std;

int pri[1000009];
int vis[1000009];

void fun()
{
    int num=0;
    for(int i=2;i<=999999;i++)
    {
        if(vis[i]==0)
        {
            pri[num++]=i;
            for(int j=i;j<=999999;j+=i)
                vis[j]=1;
        }
    }
}

int main()
{
    int n;
    fun();

    while(~scanf("%d",&n))
    {
        int num=0;
        for(int i=0;;i++)
        {
            if(pri[i]>n)break;
            else num++;
        }
        printf("%d\n",num);
    }
    return 0;
}

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

int const M=31;
int a,hantei[M];

int main(){
  hantei[0]=hantei[1]=1;
  for(int i=2;i<M;i++){
    if(hantei[i]==0){
      for(int j=2;j*i<M;j++){
	if(j*i<M){
	  hantei[j*i]=1;
	}
      }
    }
  }
  for(;cin>>a;){
    int count=0;
    for(int i=0;i<=a;i++){
      if(hantei[i]==0){
	count++;
      }
    }
    cout<<count<<endl;
  }
}

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

C++: #include <stdio.h>
 
using namespace std;
 
int calcLimit(int n){
    int limit;
    for(limit=0;limit*limit<=n;limit++);
    return limit-1;
}
 
int main(){
    int n,count,limit;
 
    while(scanf("%d",&n)!=EOF){
        count=0;
        int* array = new int[n+1];
        for(int i=1;i<=n;i++)array[i]=0;
        limit = calcLimit(n);
        for(int i=2;i<=limit;i++){
            if(array[i] == 0)
            {
                for(int j=2*i;j<=n;j+=i){
                    if(array[j]==0){
                        array[j]=1;
                        count++;
                    }
                }
            }
        }
        printf("%d\n",n-(count+1));
    }
 
    return 0;
}