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 || num == 5:
		return true
	case num < 2 || num%2 == 0 || num%5 == 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 <stdio.h>
#include <math.h>
#include <stdlib.h>
#define N 999999L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = (int) sqrt(N);
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    printf("%ld\n", count);
    if(c == EOF) break;
  }
  return 0;
}

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

int check[1000000 + 5];

void sieve()
{
check[1] = 1;
for(int i = 4; i <= 1000000; i += 2)
check[i] = 1;
for(int i = 3; i <= 1000; i += 2)
for(int j = i * i; j <= 1000000; j += i + i)
check[j] = 1;
for(int i = 1; i <= 1000000; i++)
check[i] += check[i - 1];
}

int main()
{
sieve();
int n;
while(cin >> n)
cout << n - check[n] << endl;
return 0;
}

C++: #include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>

using namespace std;

int main()
{
	int n;
	int len;
	vector<int> prime;
	
	//unsigned long t = time(NULL);
	prime.push_back(2);
	len = 1;
	for (int i = 3; i < 1000000; i += 2){
		int j;
		for (j = 0; j < len && prime[j] < i / 2; j++){
			if (i % prime[j] == 0){
				break;
			}
		}
		if (j >= prime.size() || prime[j] >= i / 2){
			prime.push_back(i);
			len++;
		}
	}
	//printf("%lu\n", time(NULL) - t);
	while (scanf("%d", &n) != EOF){
		int count;
		
		for (count = 0; prime[count] <= n; count++){//;
			//printf("%d\n", prime[count]);
			;
		}
		printf("%d\n", count);
	}
	
	return 0;
}

C++: #include<cstdio>
#include<string.h>
using namespace std;
int pNum;
bool IsPrime[1000010];
int Prime[1000010];
int GetPrime(int n){
    memset(IsPrime,true,sizeof(IsPrime));
    IsPrime[0]=IsPrime[1]=false;
    pNum=0;
    for(int i=2;i<=n;i++){
        if(IsPrime[i])Prime[++pNum]=i;
        for(int j=1;j<=pNum&&Prime[j]*i<=n;j++){
            IsPrime[Prime[j]*i]=false;
            if(i%Prime[j]==0)break;
        }
    }
    return pNum;
}
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",GetPrime(n));
    }
    return 0;
}

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

vector <int> prime;
bool is_checked[1000010] = {false};

int main() {
	// Eratosthenes
	is_checked[0] = true; is_checked[1] = true;
	for(int i = 2; i < 1000000;i++){
		if (is_checked[i]) continue;
		prime.push_back(i);
		for(int j = 1;;j++) {
			if(i*j > 1000000) break;
			is_checked[i*j] = true;
		}
	}

	int n;
	while(cin >> n) {
		int count = 0;
		for (int i = 0;;i++) {
			if (prime[i] > n) break;
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX_N 999999
int main()
{
    bool notPrime[999999+2];
    int count[999999+2];
    for (int i = 2 ; i <= 999999 ; i++)
    {
        if (!notPrime[i])
        {
            for (int g = i+i ; g <= 999999 ; g += i)
            {
                notPrime[g] = true;
            }
        }
    }
    int cnt = 0;
    count[1] = 0;
    for (int g = 2 ; g <= 999999 ; g++)
    {
        if (!notPrime[g])
            cnt ++;
        count[g] = cnt;
    }
    for(int n;cin>>n;n++){
        cout<<count[n]<<endl;
    }
    return 0;
}

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

using namespace std;
//?数表
const unsigned long long maxn=100000;//定?最大数
const unsigned long long mmax=maxn/2+1;//数?的大小
bool nprilist[mmax];//注意false才是?数
void fsetupprime()//?数表建立函数
{
    //const unsigned long long half=mmax/2+1;//定?二分??界限
    unsigned long long prei=1;//用来?存上一个起始点
    for(unsigned long long i=1;i<mmax;++i)//二分??前半段
    {
        if(!nprilist[i])
        {
            unsigned long long j=2*prei*prei+2*prei;
            while((2*j+1)%(2*i+1))
                ++j;
            for(;j<=mmax;j+=2*i+1)//j=((2i+1)^2-1)/2=2i^2+2i，i就是?里的prei，然后本来j???再加一个1的，但?了方便第一次i=3的循??一，故??里?界重?，若???要求?高，?在?里加1以?小????度
                nprilist[j]=1;
            prei=i;
        }
    }
    /*for(unsigned long long i=half;i<mmax;++i)//二分??后半段
    {
        cout<<3<<endl;
        for(unsigned long long j=1;j<half;++j)
        {
            cout<<4<<endl;
            if(nprilist[j])
                continue;
            else if(!((2*i+1LL)%(2*j+1LL)))
            {
                nprilist[i]=1;
                break;
            }
        }
    }*/
    return;
}
bool fis_prime(const unsigned long long &a)//?数判断接口函数
{
    if(a>2)
    {
        if(!(a&1))
            return 0;
        return !nprilist[(a-1)/2];
    }
    if(a==2)
        return 1;
    if(a==0||a==1)
        return 0;
}
//?数表?束


int main()
{
    fsetupprime();
    long long a=0;
    while(cin>>a)
    {
        int sum=0;
        if(a==0&&1)
            cout<<0<<endl;
        if(a==2)
            cout<<1<<endl;
        else
        {
            for(long long i=3;i<=a;i+=2)
                if(fis_prime(i))
                    ++sum;
            cout<<++sum<<endl;
        }
    }
    return 0;
}

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

using namespace std;


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

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

		for(i=2 ; i<n+1 ; i++){
			j=1;
			while(1){
				j++;
				if((i%j)==0)break;
			}
			if(i == j) count++;
		}

		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int n;
int a[1000000];
int sum[1000000];
int main(int argc, char const *argv[])
{
	for (int i = 2; i < 1000000; ++i)
	{
		if (!a[i])
		
			for (int j = i*2; j < 1000000; j+=i)
			 a[j]=1;
		}
		for (int i = 2; i <1000000 ; ++i) sum[i]=sum[i-1]+(a[i]==0?1:0);
			while (cin>>n)
				cout<<sum[n]<<endl;
				return 0;
			}
	
		
		
		
	    		
		
	}

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

using namespace std;

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

	return true;
}

int main()
{
	int N[31];
	int C[31] = { 0 };

	for (int i = 0; i < 3; i++)
	{
		for (int j = 2; j <= N[i]; j++)
		{
			if (isprime(j) == true)
			{
				C[i] += 1;
			}
		}
	}

	for (int i = 0; i < 31; i++)
	{
		cout << C[i] << endl;
	}

	return 0;
}