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++: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<int> prime(0);//i番目の素数
vector<bool> is_prime(0);//iは素数か
//n以下の素数の数
int hurui(int n){
    is_prime.resize(n+1,true);
    is_prime[0]=0; is_prime[1]=0;
    int p=0;
    REP(i,2,n+1){
        if(is_prime[i]){
            prime.emplace_back(i);
            p ++;
            for(int j=2*i; j<=n; j +=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}


int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
  hurui(1e7);
  int n;
  while(cin>>n){
      cout<<upper_bound(all(prime),n)-prime.begin()<<endl;
  }
}

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

int main(){
    int n;
    while(cin >> n){
        int numOfPrime = 0;
        bool isPrime[n-1];
        for(int i=2;i<=n;++i){
            isPrime[i-2] = true;
        }
        for(int i=2;i<=sqrt(n);++i){
            if(!isPrime[i-2]){
                continue;
            }
            for(int j=i;j<=n;++j){
                if(j%i == 0 && i != j){
                    isPrime[j-2] = false;
                }
            }
        }
        for(int i=2;i<n;++i){
            if(isPrime[i-2]){
                ++numOfPrime;
            }
        }
        cout << numOfPrime << endl;
    }
}

C++: #include <iostream>
//#include <vector>
//#include <math.h>
//#include <string>
//#include <cmath>

int main(void);
int count_prime_number(int n);

int main(){
	int n;
	int cnt = 0;
	int result[30];

	//while (cnt < 3){
		//std::cin >> n;
	while (std::cin >> n){
		result[cnt] = count_prime_number(n);
		cnt++;
	}

	for (int i = 0; i < cnt; i++){
		std::cout << result[i] << std::endl;
	}

	//while (1);
	return 0;
}


//0..nまでの素数の個数を出力する
//args:数値
//return:素数の個数
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i+= 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j+= 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

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

int main(){
    vector<int> prime;
    int n;
    for(int i=2;i<1000000;i++){
        bool isprime=true;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                isprime=false;
                break;
            }
        }
        if(isprime) prime.push_back(i);
    }
    while(cin >> n){
        for(int i=0;i<prime.size();i++){
            if(prime[i]>n){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <math.h>

using namespace std;

int main(){
  int n, count,j;
  int limit;
  vector<int> nl;
  while(cin >> n){
    nl.push_back(n);
  }

  for(int i=0; i<nl.size(); i++){
    n = nl[i];
    int prime[n+1];
    for(j=2; j<=n; j++){
      prime[j] = 1;
    }
    count = 0;
    limit = (int)sqrt(n);
    for(j=2; j<=limit; j++){
      if(prime[j] == 1){
        for(int k=j*2; k<=n; k+=j){
          prime[k] = 0;
        }
      } 
    }

    for(j=2; j<=n; j++){
      if(prime[j]==1){
        count++;
      }
    }
    cout << count << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	long long n;
	while(cin >> n){
		long long sum;
		if (n == 1)sum = 0;
		else {
			sum = 1;
			for (int i = 4; (i - 1) < n + 1; i += 4) {
				if (isprime(i - 1))sum++;
				if (isprime(i + 1))sum++;
			}
		}
		cout << sum << '\n';
	}
	return 0;
}

C++:  #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int kk[10*10];
 
 bool isPrime(int x)
 {
   for(int i=3;i<=(int)(sqrt(x));i=i+2) 
   {
     if(x%i==0) return false;        
   }    
   return true;
 }
 
 int main()
 {
   int n;
   while(cin>>n)
   {
      if(n==1) cout<<"0"<<endl;
      else if(n==2) cout<<"1"<<endl;
      else
      {
        int count=1;
        for(int i=3;i<=n;i++) if(isPrime(i)) count++;
        cout<<count<<endl;
      } 
   }
   //while(1);      
   return 0;    
 }

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

using namespace std;

bool isprime(int n) {
	if (n < 2)
		return false;
	int lim = (int)sqrt((double)n);
	for (int i = 2; i <= lim; i++)
		if (!(n%i))
			return false;
	return true;
}

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

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

int keta(int x){
	int i=0;
	while (x/pow(10,i)>=1){
		i++;
	}
	if (x==0){
		return 1;
	}
	else
	return i;
	}


int main(){
int n;
while (cin>>n){
	int yakusu=0;
	for (int i=2;i<=n;i++){
		bool flag=true;
		for (int j=2;j<i-1;j++){
			if(i%j==0){
				flag=false;
			}
		}
		if (flag){
		yakusu++;
		}

	}
cout<<yakusu<<endl;
}
return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

constexpr int LIM = 1000000;

static char isprime[LIM];
static int numofprime[LIM];

void setprime(int N) {
    fill(isprime, isprime + N + 1, 1);
    isprime[0] = isprime[1] = 0;
    for(int x = 2, lim = (int)sqrt(N); x <= lim; ++x) {
        if(isprime[x]) {
            for(int y = x * x; y <= N; y += x) {
                isprime[y] = 0;
            }
        }
    }
    numofprime[0] = 0;
    for(int x = 0; x < N; ++x) {
        numofprime[x + 1] = numofprime[x] + isprime[x + 1];
    }
}

int main() {
    setprime(999999);
    int n;
    while(scanf("%d", &n) != EOF) {
        printf("%d\n", numofprime[n]);
    }
    return 0;
}

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;

bool is_prime(int n){
	if(n<=1)return false;
	if(n==2)return true;
	if(!(n&1))return false;
	for(int x=3;x<=sqrt(n);++x) if(!(n%x))return false;
	return true;
}

int main(){
	int n;
	while(scanf("%d",&n)==1){
		int tot = 0;
		if(n>=2)++tot;
		for(int x=3;x<=n;x+=2){
			if(is_prime(x))++tot;
		}
		cout<<tot<<endl;
	}
	return 0;
}