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<iostream>
#include<cstdio>

using namespace std;

const int maxn=1e6+5;

int isprime[maxn];

int solve(int n)
{
    int p=0;
    for(int i=2;i<=n;i++){
        if(!isprime[i]){
            p++;
        }
        for(int j=2*i;j<=n;j+=i){
            isprime[j]=1;
        }
    }
    return p;
}

int main()
{
    int n;
    while(~scanf("%d",&n)){
        cout<<solve(n)<<endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
    int t;
    while(cin >> t){
        cerr << t << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

map<int, int> prime_factor(int n) {
	map<int, int> res;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int eratosthenes(int n) {
	bool is_prime[n + 1];
	memset(is_prime, true, sizeof(is_prime));
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	bool is_prime[1000001];
	memset(is_prime, true, sizeof(is_prime));
	is_prime[0] = is_prime[1] = false;
	rep(i, 2, 1000000 + 1) {
		if(is_prime[i]) {
			for(int j = 2 * i; j <= 1000000; j += i) is_prime[j] = false;
		}
	}

	int n;
	while(cin >> n) {
		int rsl = 0;
		rep(i, 0, n + 1) {
			if(is_prime[i]) rsl++;
		}
		cout << rsl << endl;
	}
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;

int main(){
	int n;
	vector<int> prime;
	int count=0;
	int tmp[3][100];
	int k=0,max=0;
	while(cin>>n){
		tmp[0][k++]=n;
		if(max<n) max = n;
		if(n==1){
			tmp[1][k-1]=0;
		}
		else if(n==2){
			tmp[1][k-1]=1;
		}
		else if(n==3){
			tmp[1][k-1]=2;
		}
	}
	//cout<<"hoge\n";
	prime.push_back(2);
	prime.push_back(3);
	//count[1]=0;
	//count[2]=1;
	//count[3]=2;
	//cout<<"hoge\n";
	count = 2;
	for(int i=4;i<max+1;i++){
		/*if(i%2==0){
			count[i]=prime.size();
		}
		else if(i%3==0){
			count[i]=prime.size();
		}
		else{
			*/
			count++;
			prime.push_back(i);
			for(int j=0;j<prime.size()-1;j++){
				if(i%prime[j]==0){
					count--;
					prime.pop_back();
					break;
				}
			}
			for(int j=0;j<k;j++){
				if(tmp[0][j]==i){
					tmp[1][j]=count;
				}
			}
		//}
	}
	//cout<<"hoge";
	/*for(int i=0;i<15;i++){
		cout<< count[i] << endl;
	}*/
	for(int j=0;j<k;j++){
		cout<<tmp[1][j]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#define N_MAX 999999


int prime[( N_MAX + 1 ) / 2 ];
int memo[ N_MAX + 1 ];

int mkprime( void );

int main( void )
{
	int n;

	prime[0] = 2;
	memo[1] = 0;
	memo[2] = 1;

	mkprime();

	while( std::cin >> n ){
		std::cout << memo[n] << std::endl;
	}
	
	return 0;
}

int mkprime( void ){
	int i, j, endindex = 1;

	for( i = 3; i < N_MAX + 1; i++ ){
		for( j = 0; prime[j] * prime[j] <= i; j++ ){
		if( i % prime[j] == 0 ){
				goto tag;
			}
		}

		prime[ endindex ] = i;
		endindex++;

tag:
		memo[i] = endindex;
	}
}

C++: #include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <vector>
#include <set>
std::vector<std::size_t> prime_table = {2};

void make_prime_table(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        // std::list<std::size_t> undefined_table;
        std::set<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            // undefined_table.push_back(i);
            undefined_table.insert(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; prime_table.back() <= sn; ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(0 == *u % prime_table[p])
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(!undefined_table.empty() && found_last_prime <= prime_table[p])
            {
                // prime_table.push_back(undefined_table.front());
                prime_table.push_back(*undefined_table.begin());
                // undefined_table.pop_front();
                undefined_table.erase(undefined_table.begin());
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
}

std::vector<size_t> prime_acc = {0};

std::size_t prime_size(const std::size_t limit)
{
    if(prime_acc.size() <= limit)
    {
        make_prime_table(limit);
        auto it = prime_table.begin();
        while(prime_acc.size() <= limit)
        {
            it = std::lower_bound(it, prime_table.end(), prime_acc.size());
            if(it != prime_table.end())
            {
                prime_acc.insert(prime_acc.end(), *it - prime_acc.size(), prime_acc.back());
                prime_acc.push_back(prime_acc.back() + 1);
            }
            else
            {
                prime_acc.insert(prime_acc.end(), limit - prime_acc.size() + 1, prime_acc.back());
            }
        }
    }
    return prime_acc[limit];
}

int main()
{
    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_size(n) << std::endl;
    }
}

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

int main() {
  const int max = 1000000;
  int isPrime[max] = {1, 1, 0};
  int i = 2;
  int n, count;

  while(i < max) {
    while(isPrime[i] != 0) {
      i++;
    }
    for(n = 2; n*i < max; n++) {
      isPrime[n*i] = 1;
    }
    i++;
  }

  while(cin >> n) {
    count = 0;
    for(n; n > 0; n--) {
      if(isPrime[n] == 0) count++;
    }
    cout << count << endl;
  }

  return 0;
}