Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [31]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<stdio.h>
 
#define MAX 1000000
 
int main(){
    char prime[MAX];
    int num, i, j, ans;
 
    for(i = 0; i < MAX; i++)
    {
        prime[i] = 1;
    }
    prime[0] = prime[1] = 0;
    for(i = 2; i < (MAX/2); i++)
    {
        if(prime[i])
        {
            for(j = 2*i; j < MAX; j += i)
            {
                prime[j] = 0;
            }
        }
    }
     
    while(scanf("%d", &num) != EOF)
    {
        ans = 0;
         
        for(i = 3; i <= num; i+=2)
        {
            ans += prime[i];
        }
         
        printf("%d\n", ans);
    }
 
    return 0;
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		long int i;
		int number[10000]={0};
		int ans=0;

		for(i=0;i<n;i++){
			if(number[i]==0){
				ans++;
				for(m=i;m<n;m+=i){
					number[i]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
	vector<int> p;
	int n;
	p.push_back(2);
	for(int i=3;i<999999;i++){
		for(int j=0;;j++){
			if(i%p[j]==0)
			break;
			if(i<p[j]*p[j]){
			p.push_back(i);
			break;
			}
		}
	}
	while(cin >> n){
		int i=0;
		while(n>=p[i]){
			i++;
		}
		cout << i << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool P[1000000];

int main() {
    int n, ans;
    while (cin >> n) {
        fill(P, P + n + 1, true);
        P[0] = P[1] = false;
        for (int i = 0; i * i <= n; i++) {
            if (P[i]) {
                for (int j = i + i; j <= n; j += i) {
                    P[j] = false;
                }
            }
        }
        ans = 0;
        for (int i = 0; i <= n; i++) if (P[i]) ans++;
        cout << ans << endl;
    }
}

C++: #include<stdio.h>
#include<math.h>
#include<cmath>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define eps 1e-8
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) (a<b?a:b)
#define ll long long
#define INF 9223372036854775807
int prime[1000005];
bool isprime[10000005];
int num;
int main()
{
    for(int i=2;i<1000005;i++)
    {
        if(isprime[i])
            continue;
        prime[num++]=i;
        for(int j=2*i;j<1000005;j+=i)
        {
            isprime[j]=1;
        }
//        if(i<100)
//            printf("%d\n",prime[num-1]);
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int ans=upper_bound(prime,prime+num,n)-prime;
        printf("%d\n",ans);
    }
    return 0;
}

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

int main()
{
    std::vector<bool> is_prime(3);
    is_prime.at(0) = is_prime.at(1) = false;
    is_prime.at(2) = true;

    int n, n_max = 1;
    int cnt;
    while (std::cin >> n) {
        if (n_max < n) {
            is_prime.resize(n + 1, true);

            for (auto i = 2; i <= n / 2; i++) {
                if (is_prime.at(i) == true) {
                    for (auto j = 2 * i; j <= n; j += i) {
                        is_prime.at(j) = false;
                    }
                }
            }

            n_max = n;
        }

        cnt = 0;
        for (auto i = 2; i <= n; i++) {
            if (is_prime.at(i) == true) {
                cnt++;
            }
        }

        std::cout << cnt << std::endl;
    }

    return 0;
}

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

int main(){
int n;
while(cin>>n){
	if(n==0)break;
	int m=0;
    for(int i=1;i<=n;i++){
    	int s=0;
    	if(i==1)s=1;
    	if(i>3){
    		for(int j=2;j<=sqrt(i);j++){
    			if(i%j==0)s=1;
    		}
    	}
    	if(s==0)m++;
    }
	cout<<m<<endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
    int n, ans, cnt, prime;

    while(cin >> n){
      prime = 1;
      if(n == 1) cout << 0 << endl;
      if(n == 2) cout << 1 << endl;
      if(n == 3) cout << 2 << endl;

      if(n >= 4){
      for(int i=3; i <= n; i++){
        cnt = 0;
        for(int j=3; j <= sqrt(i); j += 2){
          if(i%j == 0) cnt++;
        }
        if(cnt == 0  && i%2 != 0) prime++;
      }
      cout << prime << endl;
    }
    }
    return 0;
}

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

int pn[1000002];

int main(){
int n, Count;
cin.tie(0);
while(scanf("%d",&n)!=EOF){
Count=0;
memset(pn,0,n);
pn[0]=pn[1]=1;
for(int i=2;i<=n;i++) if(!pn[i]) for(int j=1;i*j<=n;j++) pn[i*j]=1;
for(int i=2;i<=n;i++) if(!pn[i]) Count++;
cout<<Count<<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)//二分??前半段
    {
        cout<<0<<endl;
        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;cout<<"1"<<endl;}
            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>
int m,n,p;void r(){p++;if(m<2)p--;else{for(int i=3;i*i<=m;i+=2)if(m%i==0){p--;break;}}}int main(){for(;!(std::cin>>n).eof();){if(n<3)p=!(n-2);else for(m=3,p=1;m<=n;m+=2)r();printf("%d\n",p);}}

C++: #include<iostream>
using namespace std;
int main()
{
	int n,S;
while(cin>>n)
{
	S=0;
	if(n==1)
	{
		cout<<0<<endl;
	}
	else if(n>=2)
	{
		S++;
	}
	else
	{
	for(int i=2;i<=n;i++)
	{
		for(int j=i-1;j>1;j--)
		{
			if(i%j==0)
			{
				break;
			}
			if(j==2)
		{
			S++;
		}
		}	
			
	}
}
	cout<<S<<endl;
}
return 0;
}