Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]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 <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;
}

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