Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [40]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<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1000000

static bool gosei[MAX];

void b(){
	for(int i=2;gosei[i]==false&&i<MAX;i++)
		for(int j=2,k;(k=i*j)<MAX;j++)
			gosei[k]=true;
}

int c(int n){
	int cnt=0;
	for(int i=2;i<=n;i++)
		if(!(gosei[i]))cnt++;
	return cnt;
}

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

C++: #include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 _Bool *list;
 int n,i,j,cnt;
 
 while(scanf("%d",&n) != EOF)
 {
  cnt = 0;
  list = (int*)calloc(n+1,sizeof(int));
  for(i = 2; i <= n; i++)
  {
   if(list[i] != 1) /*prime number:0 no prime numbers:1*/
   { 
    cnt++;
    for(j = i+i; j <= n; j+=i) list[j] = 1;
   }
  }
  printf("%d\n",cnt);
  free(list);
 } 
 return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#define LIMIT 1000000

int main(){
	int num;
	while( scanf("%d",&num)!=EOF ){
		bool sosu[LIMIT]={0};
		int now=2,count=0;
		while(now<=num){
			if(!sosu[now]){
				count++;
				for(int i=now;i<LIMIT;i+=now){
					sosu[i] = true;
				}
			}
			now++;
		}
		std::cout << count << std::endl;
	}
	return 0;
}

C++: #include <stdio.h>

#define MAX (100000)

int main(void)
{
	int prime[MAX + 1] = {1};
	int n;
	int ans;
	int i;
	char str[100];
	
	for (int i = 0; i <= MAX; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	i = 0;
	while (i * i <= MAX){
		while (prime[++i] != 1 && i * i <= MAX);
		//printf("%d ", i);
		for (int j = 2; j * i <= MAX; j++){
			//printf("%d\n", i * j);
			prime[i * j] = 0;
		}
	}
	
	while (fgets(str, 100, stdin)){
		sscanf(str, "%d", &n);
		
		ans = 0;
		for (int i = 2; i <= n; i++){
			if (prime[i] == 1){
				ans++;
			}
		}
	
		printf("%d\n", ans);
	}
	
	return (0);
}

C++: #include <iostream>
#include <cmath>
//#include <ctime>
#define Even(n) n%2
using namespace std;

void count_Prime(int n);
bool IsPrime(int num);


int main()
{
	int Data = 0;
//	clock_t start, end;
	while (cin >> Data)
	{
//		start = clock();
		count_Prime(Data);
//		end = clock();

		cout << (double)(end - start) / CLOCKS_PER_SEC << "sec" << endl;
	}

	return 0;
}

void count_Prime(int n)
{
	int counter = 0,  i = 0;
	for (i = 2; i <= n; ++i)
	{
		if (IsPrime(i))
			counter++;
	}

	cout << counter << endl;

}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // ??¶??°????????????????????????

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// ?´???°??§?????????
			return false;
		}
	}

	// ?´???°??§??????
	return true;
}

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

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

	return 0;
}

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

const int MAX_N = 999999;
bool prime[MAX_N + 1];

void sieve()
{
  prime[0] = prime[1] = false;
  for(int i = 2; i <= MAX_N; ++i)
    prime[i] = true;
  for(int i = 2; i <= MAX_N; ++i)
    if(prime[i])
      for(int j = i * 2; j <= MAX_N; j += i)
	prime[j] = false;
}

int is_prime(int n)
{
  return prime[n];
}

int main()
{
  int n, i;
  int ans = 0;
  sieve();
  while(cin >> n){
    for(i = 0; i < n; i++){
      if(is_prime(i)){
	ans++;
      }
    }
    if(i == n){
      break;
    }
  }
  printf("%d\n", ans);
}

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

static const int MAX = 1000000;

void make_prime(bool *n){
    for (int i=2; i<1000; i++) {
        if (!n[i]){
            for(int j = i*i; j < MAX; j+=i){
                n[j] = true;
            }
        }
    }
}

int main(){
    bool num[MAX] = {false};
    make_prime(num);
    int n;
    while(cin >>n){
        int ans = 0;
        for(int i=2; i<=n; i++){
            if(!num[i]){ans++;}
        }
        cout <<ans<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int i,j,n,count,prime;

    while(cin >> n){
        prime = 0;
        for(i = n;i > 1;i--){
            count = 0;
            for(j = 2;j <= sqrt(i);j++){
                if(i % j == 0){
                    count++;
                }
            }
            if(count == 0){
                prime++;
            }
        }
        cout << prime << endl;
    }
    
    return 0;
}

C++: import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		Boorean[] bit = new Boorean[1000000];
		Arrays.fill(bit, true);
		bit[0] = false;
		bit[1] = false;

		for(int i=2; i<1000; ++i){
			if(bit[i]){
				for(int j=i*2; j<1000000; j+=i)
					bit[j] = false;
			}
		}

		int[] prime = new int[1000000];
		prime[0] = 0;
		for(int i=1; i<1000000; ++i)
			prime[i] = prime[i-1] + (bit[i] ? 1 : 0);

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String str;
		try{
			while((str = bf.readLine()) != null){
				int n = Integer.parseInt(str);
				System.out.println(prime[n]);
			}
		}
		catch(IOException ex){
			System.out.println(ex);
		}
	}
}

C++: import sys


def prime(x):
    for i in p_list:
        if x % i == 0:
            return 0
    return 1


if __name__ == "__main__":
    a = 10000
    i = 2
    p_list = []
    while i < a:
        if prime(i):
            p_list.append(i)
        i += 1
    print(p_list)

    for i in sys.stdin:
        n = int(i)
        while 1:
            if n not in p_list:
                n -= 1
            else:
                print(p_list.index(n) + 1)

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

using namespace std;
static const int MAXV = 1000000;

int sosuu_list[MAXV];

void make_sosuu_list() {
  for(int i=0;i<MAXV;i++) sosuu_list[i] = 1;
  sosuu_list[0] = sosuu_list[1] = 0;
  for(int i=2;i<MAXV;i++) {
    if(sosuu_list[i]) {
      for(int j=i+i;j<MAXV;j+=i) sosuu_list[j] = 0;
    }
  }
  for(int i=1;i<MAXV;i++)sosuu_list[i]+=sosuu_list[i-1];
}

int main() {
  int n;
  make_sosuu_list();
  while(!feof(stdin)) {
    scanf("%d", &n);
    if(feof(stdin)) break;
    printf("%d\n", sosuu_list[n-1]);
  }
}

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

using namespace std;

bool p[1000000];

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

    p[0] = p[1] = false;

    for (int i = 2; i < sqrt(999999); i++) {
        if (p[i]) {
            for (int j = i * 2; j < 1000000; j += i) {
                p[j] = false;
            }
        }
    }
}

int main() {
    primes();

    int n;
    while (cin >> n) {
        int ans = 0;
        for (int i = 2; i <= n; i++) {
            if (p[i]) {
                ans += 1;
            }
        }

        cout << ans << endl;
    }

    return 0;
}