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<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int cnt=0,res=0;
    for(int i=3; i<=n; i+=2){
      for(int j=1; j<=i; j++){
        if(i%j == 0) cnt++;
      }
      if(cnt==2) res++;
      cnt = 0;
    }
    cout << res+1 << endl;
  }
  return 0;
}

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

int eratos(forward_list<int> xs) {
	if (xs.empty()) return 0;
	int head = xs.front();
	xs.pop_front();
	xs.remove_if([&](int n){
		    return !(n%head);
		    });
	return 1+eratos(xs);
}

int main() {
	int n;
	while (cin>>n) {
		forward_list<int> ls(n-1);
		iota(begin(ls),end(ls),2);
		cout << eratos(ls) << endl;
	}
	return 0;
}

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,max;
	int count[N_MAX];
	bool so[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		so[i]=true;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	so[0]=so[1]=false;
	for(j=4;j<=max;j+=2)
			so[j]=false;
	for(i=3;i<=1000;i+=2){
		if(so[i]==0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=false;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;
	while(cin >> n){
		count = 0;
		for(int i = 2; i <= n; i++){
			if(i == 2){
				count++;
			}
			else if(i % 2 != 0){
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
						break;
					}
				}
				if(flag != true){
					count++;
				}
				flag = false;
			}
		}

		cout << count << endl;

	}

	return 0;
}

C++: #include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(void)
{
  int i=0;
  int j=0;
  int n=0;
  int a[1000000]={};
  int sum=0;

  while(scanf("%d",&n)!=EOF)
    {
      for(i=0;i<1000000;i++)
        a[i]=1;
      sum=0;

      for(i=2;i<=n;i++)
        {
          if(a[i-1]==0)
            continue;
          for(j=2;j<=n/i;j++)
            a[i*j-1]=0;
        }

      for(i=1;i<n;i++)
        sum+=a[i];

      cout<<sum<<endl;

    }


  return 0;

}

C++: #include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
bool isprime[1000000];
vector<lnt> primes;

int main()
{
	fill(isprime,isprime+1000000,1);
	isprime[0]=isprime[1]=0;
	for(lnt i=2;i<1000000;i++){
		if(!isprime[i]) continue;
		primes.push_back(i);
		for(lnt j=2*i;j<1000000;j+=i) isprime[j]=0;
	}
	lnt n;
	while(scanf("%lld",&n)!=EOF){
		cout<<upper_bound(primes.begin(),primes.end(),n)-primes.begin()<<endl;
	}
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 1;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 1;
	for (int i = 1;i<=num;i++) {
		
		for (int j=2;j<i;j++) {
			if (i%j==0) {
				count ++;
				break;
			}
			
		}
	}
	cout << (num-count) <<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
 
int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

	for(int i=3; i*i<=n; i+=2){
		if(n%i==0){
			return 0;
		}
	}
	return 1;

}

//0009
int main()
{
	int n;
 
	while(cin >> n){
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}

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

bool prime_number(int n);
int proceed;
bool pn[1000000];

int main(int argc, char** argv) {
	int n, i, result;

	while(std::cin >> n) {
		if(n < 2) {
			result = 0;
		}else {
			result = 1;
			for(i = 3; i <= n; i += 2) {
				if(prime_number(i)) {
					result++;
				}
			}
		}
		std::cout << result << std::endl;
	}
}

bool prime_number(int n) {
	if(n <= proceed){
		return pn[n];
	}
	proceed = n;
	int i;
	double rt = sqrt(n);
	if(n < 2) {
		return false;
	}else if(n == 2) {
		pn[2] = true;
		return true;
	}else if(n % 2 == 0) {
		return false;
	}
	for(i = 3; i <= rt; i += 2) {
		if(n % i == 0) {
			return false;
		}
	}
	pn[n] = true;
	return true;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;

int prime[1000000];
bool is_prime[1000000];
int seive(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;
	while(cin>>n){
		cout<<seive(n)<<endl;
	}
}

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

int prime[1000000] = {1};

int main()
{
  int n;
  prime[0] = prime[1] = 0;
  for (int i = 2; i < 1000000; i++){
    if (prime[i] == 1){
      for (int j = 2 * i; i < 1000000; j += i){
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < 1000000; i++){
    prime[i + i] += prime[i];
  }
  while (cin >> n){
    cout << prime[n];
  }

  return 0;
}

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

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

int main(){
	int input;
	std::vector<int> answer;
	
	
	//for (int i = 0; i < 3; i++){
		//std::cin >> input;
	while (std::cin >> input){
		answer.push_back(count_prime_number(input));
	}

	for (int i = 0; i < answer.size(); i++){
		std::cout << answer[i] << std::endl;
	}

	//while (1);
	return 0;
}

/**
* nまでの素数の個数を出力する
* args:数値n
* return:素数の個数
* 参考:http://tsg.ne.jp/TT/tsg/c/mansaku/P01.html
*/
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;
}