Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [40]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 <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long;

const int MAXN = 1000000;

int tot; bool vis[MAXN];
int prime[MAXN];

void init() {
    for(int i = 2; i < MAXN; ++i) {
        if(!vis[i]) prime[tot++] = i;
        for(int j = 0; j < tot; ++j) {
            if(i*prime[j] >= MAXN) break;
            vis[i*prime[j]] = true;
            if(i%prime[j] == 0) break;
        }
    }
}

int main() {
    init();
    int n;
    while(~scanf("%d", &n)) {
        printf("%d\n", upper_bound(prime, prime+tot, n) - prime);
    }
    return 0;
}

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

class CheckList{
public: 
    int candidateNumber;
    bool isPrime;
public:
    CheckList();
    CheckList(int number);
};

CheckList::CheckList(int number){
    candidateNumber = number;
    isPrime = true;
}

CheckList::CheckList(){
    candidateNumber = 0;
    isPrime = true;
}

int main(){
    int n;
    while(cin >> n){
        vector<CheckList> list(n-1);
        for(int i=2;i<=n;++i){
            CheckList number(i);
            list[i-2] = number;
        }
        for(int i=2;i<=sqrt(n);++i){
            if(!list[i-2].isPrime){
                continue;
            }
            for(int j=i;j<=n;++j){
                if(j%i == 0 && i != j){
                    list[j-2].isPrime = false;
                    continue;
                }
            }
        }
        for(vector<CheckList>::iterator it = list.begin();it!=list.end();){
            if(!(*it).isPrime){
                it = list.erase(it);
                continue;
            }
            it++;
        }
        cout << list.size() << endl;
    }
}

C++: #include<iostream>
#include<cmath>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int prime(int x) {
    int ret = 0;
	for(int i = x; i > 1; i--) {
		int n = (int)sqrt(i);
		int yakusu = 0;
		for(int j = 1; j<=n; j++) {
			if(i%j==0) yakusu++;
		}
		if (yakusu==1) {
			ret++;
		}
	}
	return ret;
}

int main(){
    int x;
    while(cin>>x){
        cout << prime(x) << endl;
    }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>

using namespace std;


int main(){
	int n = 0;
	int count;
	bool flag = false;
	while(cin >> n){
		count = 0;
		for(int i = 1; i <= n; i++){
			if(i < 2);
			else if(i == 2){
				count++;
			}
			else if(i % 2 != 0){
				for(int j = 3; j * j <= i; j += 2){
					if(i % j == 0){
						flag = true;
					}
				}
				if(flag != true){
					count++;
				}
			}
			flag = false;
		}

		cout << count << endl;
		

	}

	return 0;
}

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

int main(){
	int n=0,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)==1){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0) p=true;
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	}
	return 0;
}

C++: #include <cstdio>
int d[1000000],c[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<=999999;i++) {
		if(d[i]){c[i]=r;continue;}
		c[i]=++r;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n]);
	}
}

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

const int MAX_N = 1000000;

vector<int> init(void){
    vector<int> prime;
    bool is_prime[MAX_N];
    memset(is_prime, true, MAX_N);
    
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<MAX_N; i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i; j<MAX_N; j+=i) is_prime[j] = false;
        }
    }
    return prime;
}

int main(int argc, const char * argv[])
{
    int n;
    vector<int> prime = init();
    while(cin>>n){
        cout << upper_bound(prime.begin(), prime.end(), n)-prime.begin() << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,i,j;
    int ans;
    cin >> n;
    //while(cin >> n){ 
        ans=0;
        for(i=2;i<=n;i++){
            for(j=2;j<=i;j++)
                    if(i%j==0){
                        
                        //nの因数iが素数かどうかを判定する
                        //割り切れたら素数じゃないのでループ抜ける
                        
                        break;

            }
                    //jが最終まで行けばiが素数なのでans++
                    if(j==i)ans++;
        }
        cout << ans << endl;
    //}
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#define maxn 1000000
using namespace std;
int prime[maxn],number[maxn];
void getprime()
{
    int m=sqrt(maxn+0.5);
    for(int i=2;i<=m;i++)
    {
        if(!prime[i])
        {
            for(int j=i+i;j<maxn;j+=i)
            {
                prime[j]=1;
            }
        }
    }
    int sum = 0;
    for(int i=2;i<maxn;i++)
    {
        if(!prime[i])
        {
            sum++;
        }
        number[i]=sum;
    }
}
int main ()
{
    int n;
    getprime();
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",number[n]);
    }
}
/**
--------------------- 
???zhaiqiming2010 
???CSDN 
???https://blog.csdn.net/zhaiqiming2010/article/details/62281598 
?????????????????????????
**/

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

int main() {

  int x;
  int count_cin = 0;
  while(true){
    cin >> x ;
    count_cin++;

    if(count_cin == 30) break;


    bool array[max_n];

    for(int i = 0; i < max_n; i++) {
      array[i] = true;
    }

    array[0] = false;
    array[1] = false;
    for(int i = 2; i < max_n; i++) {
      for(int j = 2; j < max_n; j++) {
        if(i * j > max_n) break;
        array[i * j] = false;
      }
    }

    int count_sosu = 0;

    for(int i = 0; i < x; i++) {
      if(array[i] == true) count_sosu++;
    }

    cout << count_sosu << endl;
  }

}