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 <bits/stdc++.h>
using namespace std;

const int N = 1e6L + 11;
int p[N];
int sum[N];

int main() {
	iota(p, p + N, 0);
	for(int i = 2; i < N; i ++) if(p[i] == i)
		for(int j = i; j < N; j += i) p[j] = i;
	for(int i = 2; i < N; i ++)
		sum[i] = sum[i - 1] + (p[i] == i);
	ios :: sync_with_stdio(false);
	int n;
	while(cin >> n)
		cout << sum[n] << '\n';
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int a[1000000]={0,0,1,2},n,k=0,count=2;
	for(int i=4;i<1000000;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){k++;break;}
		}
		if(k==0)count++;
		a[i]=count;
		k=0;
	}
	while(cin>>n)cout<<a[n]<<endl;
	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;
typedef long long LL;
const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1.0); //M_PI;

int n;
const int maxn = 10000000;
bool is[maxn];
int sum;
void f()
{
    memset(is , true , sizeof(is));
    is[0] = is[1] = false;
    int m = sqrt(maxn);
    for(int i = 2 ; i <= m ; i ++)
    {
        if(is[i])
        {
            for(int j = i * i ; j <= maxn ; j += i)
                is[j] = false;
        }
    }
}


int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    f();
    while(cin >> n)
    {
        sum = 0;
        for(int i = 0 ; i <= n ; i ++)
        {
            if(is[i])
                sum ++;
        }
        cout << sum << endl;
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

bool hurui[1000010];
int dp[1000010];

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

int main(){
    
    REP(i,1000010)hurui[i]=true;
    hurui[0]=hurui[1]=false;
    for(int i=2;i<=1000005;i++){
        if(hurui[i]){
            if(isPrime(i)){
                for(int j=i+i;j<=1000005;j+=i)hurui[j]=false;
            }
        }
    }
    
    REP(i,1000005)dp[i+1]=dp[i]+(hurui[i+1]?1:0);
    
    int t;
    while(cin>>t){
        cout<<dp[t]<<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*head < 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>
using namespace std;

int x[1000000];

int solve(int b){
    int m = 0;
    if(b == 1){
        return 0;
    }else if(b==2){
        return 1;
    }
    x[m++] = 2;
    for(int i=3;i<=b;i+=2){
        bool a = true;
        for(int j=0;j<m;j++){
            if(i%x[j]==0){
                a = false;
                break;
            }
        }
        if(a){
            x[m++] = i;
        }
    }
    return m;
}

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

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

long long int n,p[1000010],j=0,a;
int main(){
	bool isp[1000010];							  
	for(int i=0;i<=1000009;i++){
		isp[i]=true;
	}
	isp[0]=false;
	isp[1]=false;
	for(int i=2;i<=1000010;i++){
		if(isp[i]){
			p[j]=i;
			for(int k=i*2;k<1000010;k+=i){
				isp[k]=false;
			}
		}
	}
	while(cin>>n){
		a=0;
		for(int i=1;i<=n;i++){
			if(isp[i])a++;
		}
		cout<<a<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int n, cnt;
	
	while(cin >> n){
		bool prime[1000000] = {false};
		prime[1] = true; //1???????????\
		
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

C++: #include<cstdio>
using namespace std;
bool us[1000010]={false};
int p[1000010] = {0};
int main(){
    /*Eratosthenes*/
    p[0] = 2;
    for(int i = 0; i <= 1000010; i+=2){
        us[i] = true;
    }
     
    int cnt = 1;
    for(int i = 3; i <= 1000010; i+=2){
        int q = 0;
        if(us[i] == true)continue;
        else if(us[i] == false){
            p[cnt] = i;
            cnt++;
            us[i] = true;
            q = i;
            for(int j = q+q; j <= 1000010; j += q){
                us[j] = true;
            }
        }
    }
     
    int n;
    while(~scanf("%d",&n)){
        int x = 0;
        while(1){
            if(p[x] > n)break;
            x++;
        }
        printf("%d\n",x);
    }
    return 0;
}

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

int main()
{
	int count=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<0<<endl;
		}

		else{
		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				count++;
		}
		printf("%d\n",count);
		count=1;}
	}
}

C++: #include<stdio.h>
int main()
{
    long long n;
    while(scanf("%lld",&n)==1)
    {
       long long i,j,k,s=0;
       for(i=2;i<=n;i++)
    {
        k=0;
      for(j=2;j*j<=i;j++)
      {
          if(i%j==0)
          {
              k=1;
              break;
          }
      }
       if(k==0)
          {
             ++s;
          }
    }
        printf("%lld\n",s);
    }
}