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 <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n;
bool is_prime[1000000];
int prime[1000000];

int main(int argc, char const* argv[])
{
	fill(is_prime, is_prime+1000000, true);
	is_prime[0] = false;
	is_prime[1] = false;
	int res = 0;
	for(int i = 2; i < 1000000; i++){
			if(is_prime[i]){
					res++;
					for(int j = 2; j * i < 1000000; j++){
							is_prime[j * i] = false;
					}
			}
			prime[i] = res;
	}
	while(cin >> n){
			cout << prime[n] << endl;
	}
	return 0;
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool prime[1000000];
	rep(i,1000000)prime[i]=true;
	prime[0]=prime[1]=false;
	loop(i,2,1000){
		for(int j=i*2;j<1000000;j+=i){
			prime[j]=false;
		}
	}
	int n;
	while(cin>>n){
		int cnt=0;
		rep(i,n+1){
			if(prime[i])cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

int main(void) {
  int table[MAX_NUM + 1] = {0};
  for(int i = 2; i < MAX_NUM; i++) {
    for(int j = i * 2; j < MAX_NUM; j = j + i) {
      table[j] = 1;
    }
  }

  int num;
  int ans = 0;
  while(cin >> num) {
    for(int i = 2; i <= num; i++) {
      if(table[i] == 0) {
        ans++;
      }
    }
    cout << ans << endl;
    ans = 0;
  }

  return 0;
}

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

int get_num_of_under_n(int n) {
	bool* numbers = new bool[n + 1];
	for (int i = 2; i < n + 1; i++) {
		numbers[i] = true;
	}
	for (int i = 2; i < sqrt(n); i++) {
		if (numbers[i] == true) {
			for (int j = 0; i*(j + 2) <= n; j++) {
				numbers[i*(j + 2)] = false;
			}
		}
	}
	int ans = 0;
	for (int i = 2; i < n + 1; i++) {
		if (numbers[i] == true)ans++;
	}
	return ans;
}
int main() {
	int n;
	while (cin>>n) {
		cout << get_num_of_under_n(n)<<endl;
	}
}

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

using namespace std;

typedef unsigned int U;

const U R = 1000000;
bool isp[R];
vector<U> primes;

void elatos(){
  memset(isp , 1 , sizeof(isp));
  U n = 0;
  for(U i=2; i < R; i++)
    if(isp[i])
      for(U j=2*i; j < R; j+=i) isp[j] = 0;
  for(U i=2; i<R; i++) if(isp[i]) primes.push_back(i);
}

int main(){
  elatos();
  int n;
  while(cin >> n){
    vector<U>::iterator it = lower_bound(primes.begin(), primes.end() , n);
    cout << it - primes.begin() << endl;
  }
  return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));


	for (int i = 2; i <= MAX; i++){
		if (!vis[i]){

			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;

			}
		}
	}
	int sum = 0;
	for (int i = 2; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}

	int n;
	while (cin >> n){
	cout << amount[n] << endl;
}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

int cntPrime(int n) {
	int cnt = 0, i, k;
	for(i = 2; i <= n; i++) {
		cnt += prime(i);
	}
	return cnt;
}

int main() {
	int a;
	int arg[1024] = { 0 };
	int cnt = 0;
	while(scanf("%d", &a) != EOF) {
		printf("%d\n", cntPrime(a));
	}
	int i;
	for(i = 0; i < cnt; i++) {
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define ll long long int

#define rep(p,q) for(int i = p; i < q;i++)


void eratos(bool isPrime[10000000]) {
	
	rep(0, 10000000)isPrime[i] = true;
	rep(2, 10000000) {
		if (!isPrime[i])continue;
		else {
			for (int j = i * 2; j < 10000000; j += i) {
				isPrime[j] = false;
			}
		}
	}
}

//9

int main(void) {
	static bool isPrime[10000000];
	eratos(isPrime);
	static int countPrime[10000000];
	countPrime[0] = 0;
	countPrime[1] = 0;
	rep(2, 10000000) {
		if (isPrime[i])countPrime[i] = countPrime[i - 1] + 1;
		else countPrime[i] = countPrime[i - 1];
	}
	int n;
	while (cin >> n) {
		cout << countPrime[n] << endl;
	}

}

C++: int main() {
	bool isPrime[1000000] = {true};

	for (int i = 0; i < 1000000; i++) {
		isPrime[i] = true;
	}

	isPrime[1] = false;
	for (int i = 2; i < 1000000; i++) {
		if (!isPrime[i])
			continue;

		if (isPrime[i]) {
			int k = 2*i;
			while (k < 1000000) {
				isPrime[k] = false;
				k += i;
			}
		}
	}

	int n;
	while (cin >> n) {
		int sum = 0;
		for (int i = 2; i <= n; i++) {
			if (isPrime[i])
				sum++;
		}
		cout << sum << endl;
	}

	return 0;
}

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

bool prime(int a) {
	for (int b = 3;; b += 2) {
		if (a%b == 0)return false;
		if ((b + 1)*(b + 1) > a)return true;
	}
}
int main() {
	while (1) {
		int s = 0;
		int a;
		cin >> a;
		if (cin.fail())break;
		if (a > 1)s++;
		if (a > 2)s++;
		for (int b = 5; b <= a; b+=2) {
			if (prime(b))s++;
		}
		cout << s << endl;
	}
}

C++: #include <iostream>
using namespace std;
int main() {
	int n, count = 0;
	while(cin >> n) {
		for(int i = 2; i <= n; i++) {
			for(int j = 2; j < i; j++) {
				if(i % j == 0) {
					count--;
					break;
				}
			}
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

bool flag[10000001];

int main(){
	int n = 0, ans = 0;
	
	for (int i = 0; i <= 1000000; i++){
		if (i <= 1) flag[i] = false;
		else flag[i] = true;
	}
	for (int i = 2; i <= 1001; i++){
		if(flag[i] == true){
			for(int j = i * 2; j <= 1000000; j += i){
				flag[j] = false;
			}
		}
	}
	while(cin >> n){
		ans = 0;
		for(int i = 0; i <= n; i++){
			if(flag[i] == true){
				ans++;
			}
		}
		cout << ans << endl;
	}
 }

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

using namespace std;

int main()
{
    vector<int> ans(0);
    bool p[999999]; for (int i=0; i<999999; i++) p[i]=true;
    p[1]=false;
    int sum=0, n;
    for (int i=2; i<998; i++)
    {
        for (int j=i+i; j<=999999; j+=i) p[j]=false;
    }
    while (cin>>n)
    {
        for (int i=1; i<=n; i++) if (p[i]) sum++;
        ans.push_back(sum);
        sum=0;
    }
    for (int i=0; i<ans.size(); i++) cout<<ans[i]<<'\n';
    return 0;
}

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

int whether(int num);
int count(int num);

int main(){
	int n;
	int a;
	clock_t c, d;

	while(1){
		if(scanf("%d",&n) == -1) break;
		a = count(n);
		printf("%d\n",a); 
}

	return 0;
}

int whether(int num){
	int s=sqrt(num);
	int i;
	for(i=3; i<=s; i+=2){ if(num%i==0) return 0; }

	return 1;
}

int count(int num){
	int a=1;
	int i;
	if(num <2){ return 0; }
	for(i=3; i<=num; i+=2){
		a += whether(i);
	}

	return a;
}