Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

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
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <string>
#include <complex>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

typedef long long ll;
typedef vector<int> vi;

const int MAX_N = 1000000;
bool prime[1000000];
int np[1000000];

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

	fill(np, np+MAX_N, 0);
	for(int i=1; i<=MAX_N; i++) {
		if(prime[i]) {
			np[i] = np[i-1] + 1;
		} else {
			np[i] = np[i-1];
		}
	}
}

int main() {
	eratosthenes();

	int n;
	while(scanf("%d\n", &n)!=EOF) {
		printf("%d\n", np[n]);
	}
}

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

using namespace std;

const int N_MAX = 1000000;

int table[N_MAX];

int main() {
  table[0] = table[1] = 1;
  int sq = sqrt(N_MAX);
  for (int i = 2; i < sq; i++) {
    if (table[i] == 0) {
      for (int j = i*2; j < N_MAX; j += i) {
        table[j] = 1;
      }
    }
  }
  int n;
  while (cin >> n) {

    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (table[i] == 0) ans++;
    }
    cout << ans << endl;

  }

  return 0;
}

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

int const M=40;
int a,hantei[M];

int main(){
  hantei[0]=hantei[1]=1;
  for(int i=2;i<M;i++){
    if(hantei[i]==0){
      for(int j=2;j*i<M;j++){
	if(j*i<M){
	  hantei[j*i]=1;
	}
      }
    }
  }
  for(;cin>>a;){
    int count=0;
    for(int i=0;i<=a;i++){
      if(hantei[i]==0){
	count++;
      }
    }
    cout<<count<<endl;
  }
}

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

#define MAXN 10000000

bool is_prime[MAXN];

void sieve()
{
	for(int i=1;i<=MAXN;i++)
	  is_prime[i] = true;
	for(int i=2;i<=MAXN;i++)
	  if(is_prime[i])
	  {
	  	for(int j=2*i;j<=MAXN;j+=i)
	  	  is_prime[j] = false;
	  }
	
}
int main()
{
	sieve();
	int n;
	while(cin>>n)
	{
		int res = 0;
		for(int i=2;i<=n;i++)
		  if(is_prime[i])
		    res++;
		
		cout << res <<endl;
	}
	
}

C++: #include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int n;
int main(){
	while(cin>>n){
		int sum=0;
		if(n<=10000){
			for(int i=2;i<=n;i++){
				for(int j=2;j<=sqrt(i);j++){
					if(i%j==0){
						goto loopa;
					}
				}
				sum++;
				loopa:;
			}
			cout<<sum<<endl;
		}
		else if(n<=900000){
			for(int i=10001;i<=n;i++){
				for(int j=2;j<=sqrt(i);j++){
					if(i%j==0){
						goto loopb;
					}
				}
				sum++;
				loopb:;
			}
			cout<<sum+1229<<endl;
		}
		else{
			for(int i=900001;i<=n;i++){
				for(int j=2;j<=sqrt(i);j++){
					if(i%j==0){
						goto loopc;
					}
				}
				sum++;
				loopc:;
			}
			cout<<sum+71274<<endl;
		}
	}
	return 0;
}

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

int main(void) {

  int x;
  int count_cin = 0;
  while(true){
    cin >> x ;
    count_cin++;

    if(count_cin == 30) break;


    bool array[max_n];

    for(int i = 0; i < max_n; i++) {
      array[i] = true;
    }

    array[0] = false;
    array[1] = false;
    for(int i = 2; i < max_n; i++) {
      for(int j = 2; j < max_n; j++) {
        if(i * j > max_n) break;
        array[i * j] = false;
      }
    }

    int count_sosu = 0;

    for(int i = 0; i < x; i++) {
      if(array[i] == true) count_sosu++;
    }

    cout << count_sosu << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp;
	
	
	vector<int> isPrime;
	
	while(cin>>n)
	{
		for(int i = 0; i < n; i++){
			isPrime.push_back(1);
		}
//		cout << "Corecced!" << endl;
		isPrime[0] = isPrime[1] = 0;
		temp = 0;
		
		for(;;)
		{
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i < n; i++){
				isPrime[i*head] = 0;
			}
			
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin < head*head){
				break;
			}
			temp = head;
		}
		
		int cont = 0;
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
			}
		}
		printf("%d\n",cont);
	}
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
   int a,pp[100000];
   pp[0]=-1,pp[1]=-1;
   for(int i=2;i<100000;i++){
       if(pp[i]==0){
           pp[i]=1;
           for(int j=i*2;j<100000;j+=i){
               pp[j]=-1;
           }
       }
   }
   int now;
   while(cin>>now){
       int ans=0;
       for(int i=1;i<now+1;i++){
           if(pp[i]==1){
               ans++;
           }
       }
       cout<<ans<<endl;
   }
    return 0;
}

C++: #include <stdio.h>
int main()
{
    int low, high, i, flag,c=0,s;
    while(scanf("%d",&high)==!EOF)
       {
           int start = 2;

            while (start <= high)
            {
                flag = 0;
                s = sqrt(start);


                    for(i = 2; i <= start/2; i++)
                    {

                        if(start % i == 0)
                        {
                            flag = 1;
                            break;
                        }
                    }

                    if (flag == 0)
                    {
                          c++;

                    }
                    start++;

            }
                printf("%d\n",c); c=0;



       }
    return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int prime[1000000] = {0};
    int k = 1;
    prime[0] = 2;
    for (long long int i = 3; i < 999999; i++)
    {
        double temp = sqrt(i);
        for (int j = 0; i % prime[j] != 0; j++)
        {
            if (temp < prime[j])
            {
                prime[k++] = i;
                break;
            }
        }
    }
    int n;
    int i;
    while (cin >> n)
    {
        i = 0;
        while (true)
        {
            if (n < prime[i])
            {
                break;
            }
            i++;
        }
        cout << i << endl;
    }
    return 0;
}