Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

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;
}

C++: #include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;

bool is_prime[10000001];

int main(){
    int N;
    while(cin >> N){
    for(int i = 2; i <= N; i++){
        is_prime[i] = true;
    }

    for(int i = 2; i <= N; i++){
        if(!is_prime[i]){
            continue;
        }
        for(int j = 2 * i; j <= N; j += i){
            is_prime[j] = false;
        }
    }

    int ans = 0;
    for(int i = 2; i <= N; i++){
        if(is_prime[i]){
            ans++;
        }
    }
    cout << ans << endl;
    }
}

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

int is_it_primeNum(int n)
{
	int a = 1;
	if (n == 0 || n == 1)
		return 0;
	else if (n == 2)
		return 1;
	else if(n % 2 == 0)
		return 0;
	else{ 
		for(int i=3;i<n/2;i+=2){
			if (n%i==0){
				a = 0;
				break;}
		}
	}
	return a;
}
int how_much_primeNum(int n)
{
	int ans = 0;
	for(int i=2;i<=n;i++){
		ans += is_it_primeNum(i);
	}
	return ans;
}

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

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

int main(){
	int n[1000000]={0};
	int x, ans=0;
	
	for(int i=1; i<999999; i++){
		if(i==1) n[i]=-1;
		else if(n[i]==0){
			for(int k=2; k*i<999999; k++){
				n[k*i]=-1;
			}
		}
	}
	
	while(cin>>x){
		ans=x;
		for(int j=1; j<=x; j++) ans+=n[j];
		cout << ans << endl;
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-10;

int main(){
	vector<int> p;
	vector<int> a(1000000);
	bool b;
	int n = 1000000;

	a[0] = a[1] = 0;
	a[2] = 1;
	p.push_back(2);
	for(int i = 3; i < n; i++){
		b = true;
		for(int j = 0; j < p.size(); j++){
			if(p[j]*p[j] > i){
				break;
			}
			if(i % p[j] == 0){
				b = false;
				break;
			}
		}
		if(b){
			p.push_back(i);
		}
		a[i] = p.size();
	}

	while(cin >> n){

		cout << a[n] << endl;
	}

	return 0;
}

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+1; 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<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	c[0]=c[1]=0;
	for(i=2;i<100000;i++){
		c[i]=1;
	}

	while((scanf("%d",&n)!=EOF)&&(n!=0)){
		
		count=0;
		for(i=0;i*i<=n;i++){
			data[i]=count;
			if(c[i]==1){
				count++;
				for(j=i+1;j<=n;j++){
					if(j%i==0){

					}
				}
			}
		}

		printf("%d",data[n]);
	}
	return 0;
}

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

bool prime(int n);

int main(void) {
	using namespace std;
	int x;
	int count;
	while (cin >> x) {
		count = 0;
		for (int i = x; i > 1; i--) {
			if (prime(i))count++;
		}
		cout << count << endl;
	}
	return 0;
}

bool prime(int n) {
	for (int i = 2; i <= pow((double)n,0.5); i++) {
		if (n % i == 0)return false;
	}
	return true;
}