Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [40]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<list>
#include <vector>
#include <numeric>
#include <algorithm> 
using namespace std;

int main(){
	int N;
	int r;
	int j;
	int count;
	list<int> counter;
	
	while(!(cin>>N).eof()){
		if(N==2 ){
			counter.push_back(1);
		}
		else if(N==3){
			counter.push_back(2);
		}
		else {
			count=0;
			for(int i=3; i<=N; i+=2){
				j=3;
				do{
					r = i%j;
					if(j!=3 && r == 0) break;
					j+=2;
				}while(j<=(i/2)+1);
				if(i!=3 && r==0) continue;
				count++;
				
			}
			counter.push_back(count);
		}	
	}
	list<int>::iterator it = counter.begin();
	while(it != counter.end()){
		cout << *it << endl;
		it++;
	}
	return 0;
}

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

//素数かどうか判定する関数
bool judge( int x )
{

    for( int i = 2; i <= x - 1; i++ )       //ex与えられた数が10なら
    {                                       //2~9までの数で割り切れたら、素数ではない。
        if( x % i == 0)
            return false;
    }

    return true;
}

int main()
{
    int n;

    while( cin >> n )                           //2が素数であることを予め考慮
    {
        int count = 1;                          //countは素数の数なので、1

        if( n <= 1 )                            //nが1以下なら素数の数は0
        {
            count = 0;
        }

        for( int i = 3; i <= n; i += 2 )        //3以上の自然数について、奇数のみ素数判定を行う
        {
            if( judge(i) )
                count++;
        }

        cout << count << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7+1;
int prime[maxn];
bool is_prime[maxn];

int sieve(int n) {
    int p = 0;
    for(int i = 1; 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 = i+i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return p;
}

int main() {
    int n;
    while(scanf("%d", &n) != EOF) {
        printf("%d\n", sieve(n));
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define debug(n) cout<<"# "<<#n<<": "<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	for(int n;cin>>n;){
		deque<bool> is_prime(n+1,true);
		is_prime[0]=is_prime[1]=false;
		repi(i,2,is_prime.size()){
			if(is_prime[i])
				for(int j=i+i;j<is_prime.size();j+=i)
					is_prime[j]=false;
		}
		cout<<count(allof(is_prime),true)<<endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

bool is_prime[1000000];
int prime[1000000];

int main() {
	int n;
	rep(i, 1000000)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	int p = 0;
	for (int i = 2; i < 1000000; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j < 1000000; j += i)is_prime[j] = false;
		}
	}
	while (cin >> n) {
		cout << upper_bound(prime, prime + p, n) - prime << endl;
	}
	return 0;
}

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]){
			is_prime[i] = 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>
using namespace std;

int main() {
	int n, ans; bool not_prime[1000000 + 1];
	not_prime[0] = true;
	not_prime[1] = true;
	for (int i = 2; i <= sqrt(1000000); i++) {
		if (not_prime[i] != true) {
			for (int j = i * 2; j <= 1000000; j += i) {
				not_prime[j] = true;
			}
		}
	}
	for (int i = 0; i < 1000000 + 1; i++) {
		if (not_prime[i] != true) { not_prime[i] = false; }
	}
	while (cin >> n) {
		ans = 0;
		for (int i = 2; i <= n; i++) {
			if (not_prime[i] == false) { ans++; }
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
	long n;
	cin >> n;
	//n = 1;
	long cnt = 0;
	for (long i = 0; i < n; i++){
		long m;
		cin >> m;
		//m = 4;
		bool p = 1;
		long o;
		o = sqrt(m);
		for (long j = 0; j < o; j++){
			if (j > 0 && m % (j + 1) == 0){
				p = 0;
				break;
			}
		}
		if (p == 1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#define N 1000000
int main(void) {
	int prime[N] = { 0 }, sums[N] = { 0 }, n, sum = 0;
	prime[1] = 1;
	for (size_t i = 2; i <= sqrt(N); i++)
	{
		if (prime[i] == 0)
		{
			sum++;
			sums[i] = sum;
			for (size_t t = i + 1; t <= N; t++)
			{
				sums[t] = sum;
				if (t%i == 0)prime[t] = 1;
			}
		}
	}
	while (scanf("%d", &n) != EOF) {
		printf("%d\n", sums[n]);
	}
	return 0;
}