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

using namespace std;

#define REP(a, i, n) for (int i = a; i <= n; ++i)

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {

    int n = 0; // 999,999
    while(scanf("%d", &n) != EOF) {
        int cnt = 0;
        REP(1, i, n) {
            if (isPrime(i)) cnt++;
        }

        printf("%d\n", cnt);
    }

    return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n, ans;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << (n == 0 ? 0 : n - primes.count() - 1) << endl;
 }
  return 0;
}

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

int main() {
	std::vector<bool> isPrime(1000000, true);
	std::vector<int> numP(1000000, 0);

	isPrime[0] = false;
	isPrime[1] = false;

	for (int i = 2; i < 1000000; i++) {
		if (isPrime[i]) {
			numP[i] = numP[i - 1] + 1;
			for (int x = 2; i*x < 1000000; x++) {
				isPrime[i*x] = false;
			}
		}
		else {
			numP[i] = numP[i - 1];
		}
	}

	int input;
	while (std::cin >> input) {
		std::cout << numP[input] << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,count=0;
  while(scanf("%d",&n)!=EOF){
    if(n==0 || n==1){
      return 0;
    }
    int data[n+1];
    for(int i=2;i<=n;i++){
      data[i]=0;
    }
    for(int i=2;i<=n;i++){
      if(data[i]!=-1){
	count++;
	for(int j=i;j<=n;j+=i){
	  if(data[j]!=-1){
	  data[j]=-1;
	  }
	}
      }
    }
    cout << count << endl;
    count=0;
  }
  return(0);
}

C++: #include<stdio.h>
#include<math.h>
int main(void) {
	int prime[1000000] = { 0 }, n, sum = 0;;
	prime[1] = 1;
	while (scanf("%d", &n) != EOF) {
		for (size_t i = 2; i <= sqrt(n); i++)
		{
			if (prime[i] == 0)
			{
				for (size_t t = i + 1; t <= n; t++)
				{
					if (t%i == 0)prime[t] = 1;
				}
			}
		}
		for (size_t i = 2; i <= n; i++)
		{
			if (prime[i] == 0)sum++;
		}
		printf("%d\n", sum);
		sum = 0;
	}
	return 0;
}

C++: #include <stdio.h>
#include <math.h>

void cnt(int i) {
	int j,k,l,m;
	l=0;
	m=0;
	for(j=1;j<=i;j++){
		for(k=1;k<=sqrt(j)+1;k++){
			if(j%k == 0){
				l++;
			}
		}
		if(l == 2){
			m++;
		}
		l=0;
	}
	printf("%d\n",m);
}

int main(void){
	int i;
	while (scanf("%d", &i) != EOF){
		cnt(i);
	}
}

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

int prime(int n){
  long long cnt=0;
  bool f[n+1];
  for(int i=0;i<=n;i++){
    f[i]=true;
  }
  f[0]=f[1]=false;
  for(int i=2;i<=n;i++){
    if(f[i]){
      cnt++;
      for(int j=2*i;j<=n;j+=i){
        f[j]=false;
      }
    }
  }
  return cnt;
}

int main(){
  long long n;
  while(cin >> n){
    cout << prime(n) << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

bool isprime[1000000];

int main(int argc, char **argv){
	int n;
	int cnt;
	int checkcnt = 0;
	for (int i = 0; i < 1000000; i++) {
		isprime[i] = true;
	}
	while (cin >> n && checkcnt < 30) {
		cnt = 0;
		int i;
		for (i = 2; i < sqrt(n); i++) {
			if (isprime[i]) {
				for (int j = 2; j <= n / i; j++) {
					isprime[i * j] = false;
				}
			}
		}
		for (int k = 2; k <= n; k++) {
			if (isprime[k]) {
				cnt++;
			}
		}
		cout << cnt << endl;
		checkcnt++;
	}
	return 0;
}

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

bool isPrime(int x) {
  if(x == 2) {
	return true;
  }
  
  if(x < 2 || x % 2 == 0) {
	return false;
  }
  for(int i = 3; i <= (int)sqrt(x); i += 2) {
	if(x % i == 0) {
	  return false;
	}
  }
  return true;
}

int main() {
  int n;
  bool a[1000000];

  for(int i = 1; i < 1000000; ++i) {
	if(isPrime(i)) {
	  a[i] = true;
	}
  }
  /*
  for(int i = 1; i < 10000; ++i) {
	if(isPrime(i)) {
	  cout << i << " ";
	}
  }
  */
  while(cin >> n) {
	cout << accumulate(&a[1], &a[n + 1], 0) << endl;
  }
  return 0;
}

/*-- primitive algorithm --*/
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
	if(n % i == 0) return false;
  }
  return true;
}
*/