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 ans[1000000];

int main()
{
	int n;
	int i,j;
	int an;
	while(scanf("%d",&n) != EOF){
		for(i = 0; i <= n; i++){
			ans[i] = 1;
		}
		for(i = 2; i <= 1000 && i <= n; i++){
			if(ans[i]){
				for(j = 2; i * j <= n; j++){
					ans[i * j] = 0;
				}
			}
		}
		an = 0;
		for(i = 2; i <= n; i++){
			if(ans[i]){
				an++;
			}
		}
		printf("%d\n",an);
	}
	return 0;
}

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

using namespace std;

#define MAX_N 999999
#define MAX_D 30

bool prime_check(int n, int k = 2)
{
	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	int n;

	bool isprime[MAX_N + 1];

	for (int i = 2; i < MAX_N + 1; i++)
	{
		isprime[i] = prime_check(i);
	}

	while (cin >> n)
	{
		int c = 0;

		for (int i = 2; i <= n; i++)
		{
			if (isprime[i] == true)
			{
				c++;
			}
		}

		cout << c << endl;
	}

	return 0;
}

C++: #include<iostream>
 
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

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<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
const long long int N=1000000;
vector<int> prime;
bool arr[N];
void init(){
memset(arr,true,sizeof(arr));
arr[0]=arr[1]=false;
for(int i=2;i<N;++i){
    if(arr[i])
        prime.push_back(i);
    for(int j=0;j<prime.size()&&i*prime[j]<N;j++)
    {
        arr[i*prime[j]]=false;
        if(i%prime[j]==0)
            break;
    }
}
}
int main(){
int n;
init();
while(scanf("%d",&n)!=EOF){
    int j=0;
    for(;prime[j]<=n;j++);
    printf("%d\n",j);
}
}

C++: #include<stdio.h>

int main(void)
{
	int data,i=0,j=2,k=0,l=0,kai[100]={0},s[100000]={0};

	while(scanf("%d",&data) != EOF)
	{
		if(data<0)break;
		else if(data=1)
		{
			kai[k]=0;
		}
		else
		{
			do{
				s[i]=i;
			}while(i<=data);
		    i=2;
			do		
			{
			  if(s[i] != 0)
			  {
				while(j*i<=data)
				{
					s[j*i]=0;
					j+=1;
					}
			  }
			  i+=1;
			}while(i*2<data);

			for(i=2;i<=data;i++)
			{	
				if(s[i]!=0)
				{
					kai[k]+=1;
				}
			}
		}
		k+=1;
	}

  for(j=0;j<k;j++)
    printf("%d\n",kai[j]);
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() {
  const long N = 1000000;
  vector<bool> primes(N, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i < N; i++) {
    if (!primes[i]) continue;
    for (int j = i * i; j < N; j += i)
      primes[j] = false;
  }
  vector<long> answer(N);
  answer[0] = 0;
  for (long i = 1; i < N; i++)
    answer[i] = answer[i - 1] + primes[i];
  long n;
  while (cin >> n)
    cout << answer[n] << endl;
}

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

#define MAX_NUM (1000000)

int main(void)
{
  static bool searchList[MAX_NUM];
  static bool isPrime[MAX_NUM];
  static int primeNum[MAX_NUM];
  
  double maxSq = sqrt((double)(MAX_NUM - 1));
  
  for (int i = 2; i <= maxSq + 1; i++) {
    if (searchList[i] == false) {
      isPrime[i] = true;
      for (int j = 2; j < MAX_NUM; j++) {
        if (j % i == 0) {
          searchList[j] = true;
        }
      }
    }
  }
  
  for (int i = 2; i < MAX_NUM; i++) {
    primeNum[i] = isPrime[i] ? primeNum[i - 1] + 1 : primeNum[i - 1];
  }
  
  int n;
  while (std::cin >> n) {
    std::cout << primeNum[n] << std::endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 51000000;
const int MOD = 1000000007;

//エラトステネスの篩
int prime[MAX]; //i番目の素数
bool is_prime[MAX]; //素数かどうか

int sieve(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(){
  ll n;
  while(cin>>n){
    cout<<sieve(n)<<endl;
  }
}

C++: #include <bits/stdc++.h>
#define ll long long
#define mx 1000000+7
bool a[mx+10];
ll pr[mx], p;

using namespace std;
ll sieve(ll n);
int main()
{
    ll i, j,k, l, m, n;
   while(scanf("%lld", &n)==1)
   {
       if(n == 1)
        m = 0;
       else

       m = sieve(n);
    printf("%lld\n", m);
   }

}
ll sieve(ll n)
{
   ll p = 0;
    ll i, j, k;
    k = sqrt(n);
    pr[p++] = 2;
    for(i = 4; i <= n; i+=2)
        a[i]=1;
    for(i = 3; i <= n; i+=2)
    {
        if(a[i] ==0)
            pr[p++]=i;
        if(i <= k)
            if(a[i] == 0)
        {
            for(j = i*i; j <= n; j+=2*i)
                a[j]=1;
        }
    }
    return p;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
const int inf=(1<<31)-1;

int n;
vector<bool> vec;

int main(){
	while(cin>>n){
		int ans=0;
		vec=vector<bool>(n+1,1);
		for(int i=2;i<=n;i++){
			if(vec[i]){
				ans++;
				for(int j=i;j<=n;j+=i) vec[j]=0;
			}
		}
		cout<<ans<<endl;
	}
}