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++: #include<stdio.h>
int num[1000001]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=10000001;i++)
	num[i]=1;
for(int i=2;i<=1001;i++){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int i,j,flag,n,c=0;
    scanf("%d",&n);
    for(i=2;i<=n;i++)
    {
        flag=0;
        for(j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                flag=1;
            }
        }
        if(flag==0)
        {
            c++;
        }
    }
    printf("%d",c);
    return 0;
}

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

typedef int TInt;
typedef std::vector<TInt> TList;
bool IsPrime(TInt Value, const TList& Prime)
{
    TInt Max = std::sqrt(Value);
    for(TList::const_iterator It = Prime.begin();
        It != Prime.end() && *It <= Max;
        ++It)
    {
        if(Value % (*It) == 0) return false;
    }
    return true;
}
TList GetPrimeList(TInt Max)
{
    TList Prime;
    Prime.reserve(Max);
    Prime.push_back(2);
    for(TInt i = 3; i <= Max; i += 2){
        if(IsPrime(i, Prime)){
            Prime.push_back(i);
        }
    }
    return Prime;
}
int main()
{
    TList List = GetPrimeList(999999);
    while(true){
        int n;
        std::cin >> n;
        if(std::cin.eof()) break;
        TList::iterator It = std::upper_bound(List.begin(), List.end(), n);
        std::cout << std::distance(List.begin(), It) << std::endl;
        
    }
    return 0;
}

C++: //*-*-coding:utf-8-*-*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <iterator>
#include <cmath>
#include <stack>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
  int n;

  while(cin >> n, !cin.eof()) {
    int ans = 0;
    if(n >= 2) ans++;    
    for(int i = 3; i <= n; i+=2) {
      int flag = 0;
      for(int j = 3; j <= sqrt(i); j+=2) {
	if(i % j == 0) {
	  flag = 1;
	  break;
	}
      }
      if(flag == 0) ans++;
    }    
    cout << ans << endl;
  }
  
  return 0;
}

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 <Stdio.h>

int main()
{
    int n,i,j,flag=0,cnt,h,k;
    while(scanf("%d",&n) !=EOF)
    {
        if(n==2)
            printf("1");
        else if(n==3)
            printf("2");
        else
        {
            cnt=2;
            h=n/2;
            for(k=4; k<=n; k++)
            {
                for(j=2; j<=h; j+=2)
              {
                if(k%j==0)
                {
                    flag=1;
                    break;
                }
              }
               if(flag==0)
                cnt++;
               else
               flag=0;
            }
            printf("%d",cnt-1);
        }

    }

    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 <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	int n;
	while (scanf_s("%d", &n) != EOF) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

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

int main(void)
{
	const  int MAX = 1000000;
	int number =0;
	int count = 0;
	bool noPrim[MAX];
	int p_count=0;

	for(int i=0;i<MAX;i++){
		noPrim[i]=false;
	}
	int j;
	for(int i=2;i<MAX;i++){
		if(noPrim[i]==true)break;
		j=i*2;
		while(j<MAX){
			noPrim[j]=true;
			j+=i;
		}
	}
	while(cin >>  number){
		count = 0;
		for(int i=2;i<=number;i++){
			if(noPrim[i]==false)count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>

#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
const int MAX = 10000000;
bool isPrime[MAX];
int main(){
  cin.sync_with_stdio(false);
  fill(isPrime,isPrime+MAX,true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i < MAX; ++i){
    if(isPrime[i]){
      for(int j = i*2;j < MAX;j+=i){
	isPrime[j] = false;
      }
    }
  }
  int n;
  while(cin >> n){
    int ans = 0;
    for(int i = 2;i <= n;i++){
      if(isPrime[i])ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define MAX_N 1000000

int prime[MAX_N];         // i??????????´???°
bool is_prime[MAX_N + 1]; // is_prime[i]???true????????°i????´???°

// n??\???????´???°?????°?????????
int sieve(int n) {
  int p = 0;
  for (int i = 0; i <= n; i++)
    is_prime[i] = true;
  is_prime[0] = 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(scanf("%d",&n) != EOF){
        cout << sieve(n) << endl;
    }

    return 0;
}