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 <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int setPrimeNumberCount(int n) {
    int count = 0;
    vector<int> primeList;
    vector<int> searchList;
    
    if(n >= 2){
        for(int i = 2; i <= n; i++) {
            searchList.push_back(i);
        }
        
        vector<int>::iterator end_it;
        
        for(int i = 0; i <= n; i++) {
            primeList.push_back(searchList[0]);
            
            for(vector< int >::iterator it = searchList.begin(); it != searchList.end();) {
                if(*it % primeList[count] == 0) {
                    it = searchList.erase(it);
                }
                else {
                    ++it;
                }
            }
            count++;
            if(pow(primeList[i],2) > searchList.back()) {
                for(int i = 0; i < searchList.size(); i++) {
                    primeList.push_back(searchList[i]);
                    count++;
                }
                break;
            }
        }
    }
    return count;
}

int main(void) {
    int n;
    int count = 0;
    
    while(cin >> n) {
        count = setPrimeNumberCount(n);
        cout << count << endl;
        count = 0;
    }
    return 0;
}

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

bool IsPrime(int p)
{
	for (int i = 2; i <= sqrt(p); i++)
	{
		if (p % i == 0) return false;
	}
	return true;
}

int main()
{
	int n;
	while (cin >> n)
	{
		int ans = 0;
		for (int i = 2; i <= n; i++)
		{
			if (IsPrime(i)) ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

using namespace std;

void Eratosthenes(vector<int> &S_List, vector<int> &P_List){
	vector<int>::iterator it = S_List.begin();
	P_List.push_back(*it);  //先頭を素数リストへ追加
	int num = *it;
	while (it != S_List.end()){
		if ((*it % num) == 0){
			if (S_List.empty() == false){
				it = S_List.erase(it); //探索リストから倍数を除外
				//it = S_List.begin();
			}
		}
		else{
			++it;
		}
	}
	vector<int>::iterator P_it = P_List.end();
	double p_max_sqr = sqrt(*P_it);
	vector<int>::iterator S_it = S_List.end();
	if (*S_it < p_max_sqr){
		return;
	}
	else{
		Eratosthenes(S_List, P_List);
	}
}


void output(vector<int> ex){
	vector<int>::iterator it = ex.begin();
	while(it != ex.end()){
		cout << *it << endl;
		++it;
	}
}

int main(void){
	int num;
	while (cin >> num){
		vector<int> S_List, P_List;
		for (int i=2; i<=num; ++i){
			S_List.push_back(i);
		} 
		Eratosthenes(S_List, P_List);
	}

	return 0;
}

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

inline bool isPrime(unsigned int n);

int main()
{
    int n;
    while(cin>>n){
        int count=0;
        for(int i=0; i<=n; i++){
            if(isPrime(i)) count++;
        }
        cout << count << endl;
    }

    return 0;
}

inline bool isPrime(unsigned int n)
{
    if( n==0 || n==1 ) return false;
    if( n==2 ) return true;
    if(!(n%2)) return false;
    
    int rn = static_cast<int>(sqrt(n));
    
    bool flag = true;
    for(int i=3; i<=rn; i+=2){
        if(!(n%i)){
            flag = false;
            break;
                }
    }
    return flag;
}

C++: #include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
bool prime(int cur)
{
    if(cur==1||cur==0)return false;
    for(int i=2;i<=sqrt(cur);i++)
    {
        if(cur%i==0)
        {
            return false;
        }
    }
    return true;
}
int cnt[1000005];
int main()
{
    for(int i=1;i<=1000005;i++)
    {
        if(prime(i))cnt[i]=cnt[i-1]+1;
        else cnt[i]=cnt[i-1];
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        cout<<cnt[n]<<endl;
    }
    return 0;
}

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

int main()
{
	bool is_prime[100000];
	
	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]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=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>
using namespace std;

int main(){
  int n,p[999999];
  bool ip[1000000];
  int m=0;
  for(int i=0;i<=1000000;i++) ip[i]=true;
  ip[0]=ip[1]=false;
  for(int i=2;i<=1000000;i++){
    if(ip[i]){
      p[m++]=i;
      for(int j=2*i;j<=1000000;j+=i) ip[j]=false;
    }
  }
  while(cin>>n){
    for(int i=0;i<m;i++){
      if(p[i]>n){
	cout<<i<<endl;
	break;
      }
    }
    if(n>=p[m-1]) cout<<m<<endl;
  }
  return 0;
}

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

int main(){

	const int N_MAX=100;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		count[i]=so[i]=0;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=1;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]>0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=1;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+1-so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

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

bool isPrime(int num) {
    if(num < 2) return(false);
    for(int r = 2; r * r <= num; r++) {
        if(num % r == 0) return(false);
    }
    return(true);
}

int main(void) {
    int num;
   
    while(cin >> num) {
        int prime[num + 1];
        memset(prime, -1, sizeof(prime));
        prime[0] = prime[1] = 0;
        int sum = 0;
        for(int r = 2; r <= num; r++) {
            //cout << "Eratosthenes" << endl;
            if(prime[r] != -1) continue;
            if(isPrime(r)) {
                prime[r] = 1;
                sum++;
                for(int c = r * 2; c <= num; c += r) prime[c] = 0;
            } else prime[r] = 0;
        }
        
        cout << sum << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct SieveOfEratosthenes {
    vector<int> primes;
    vector<bool> isPrime;
    void build(ll n) {
        primes.clear();
        isPrime.assign(n + 1, true);
        isPrime[0] = isPrime[1] = false;
        ll k = 2;
        for (; k * k <= n; ++k) {
            if (!isPrime[k]) continue;
            primes.push_back(k);
            for (int m = k * 2; m <= n; m += k) isPrime[m] = false;
        }
        for (; k <= n; ++k) if (isPrime[k]) primes.push_back(k);
    }
    int operator [](int i) const { return primes[i]; }
    int size() const { return primes.size(); }
};

int main() {
    int n;
    SieveOfEratosthenes soe;
    while (~scanf("%d", &n)) {
        soe.build(n);
        printf("%d\n", soe.size());
    }
}

C++: #include<stdio.h>
#include<stdlib.h>
int i,j,n;char p[1000000];
main(){
	while(scanf("%d",&n)!=EOF){
	for(i=2;i<=n;i++)
		p[i]=1;
	for(i=2;i<n;i++)
		for(j=2;i*j<=n;j++)
			p[i*j]=0;
	j=0;
	for(i=2;i<=n;i++)
		j+=p[i];
	printf("%d\n",j);
	}
}