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 <stdio.h>

#define MAX 2000000
#define UNCHECKED 0
#define PRIME 1
#define COMPO 2


bool isPrime(int n);

int main(void){
    int n;
    int primes;
    
    while (scanf("%d", &n)!=EOF){
        primes = 0;
        for (int i=2; i<=n; i++){
            if (isPrime(i)) primes++;
        }
        printf("%d\n", primes);
    }
}

bool isPrime(int n){
    static int table[MAX]={0};
    static int minPrime=2;
    
    if (n<2) return 0;
    
    do{
        if (table[n] != UNCHECKED){
            return table[n] == PRIME ? 1 : 0;
        }
        table[minPrime] = PRIME;
        for (int i=2; i*minPrime<=MAX; i++){
            table[i*minPrime] = COMPO;
        }
        while (minPrime<=MAX && table[minPrime]!=UNCHECKED) minPrime++;
    }while(minPrime<=MAX);
}

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

void MakePrimeArray(bool A[],int n){
	A[0] = A[1] = false;
	for(int i=2;i<n;i++){
		A[i] = true;
	}
	
	for(int	i=2;i*i<n;i++){
		if(A[i]){
			for(int j=i*i;j<n;j+=i){
				A[j] = false;
			}
		}
	}
}

int main(){
	
	int n=1000000;

	bool primearray[n];
	
	MakePrimeArray(primearray,n);
	
	int NumPrimeArray[n];
	
	int count=0;
	for(int i=0;i<n;i++){
		if(primearray[i]){
			count++;
		}
		NumPrimeArray[i] = count;
	}
	
	while(true){
		int innum;
		cin >> innum;
		
		if(cin.eof()) break;
		
		cout << NumPrimeArray[innum] << endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;
 
int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

	for(int i=3; i*i<=n; i+=2){
		if(n%i==0){
			return 0;
		}
	}
	return 1;

}

//0009
int main()
{
	int n;
 
	while(cin >> n){
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int prime[1000010];
bool is_prime[1000010];
int sieve(int n)
{
    int p(0);
    for(int i=0;i<=n;i++)
        is_prime[i]=1;
    is_prime[0]=is_prime[1]=0;
    for(int i=2;i<=n;i++)
    {
        if(is_prime[i])
        {
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i)
                is_prime[j]=0;
        }
    }
    return p;
}
int main()
{
    //freopen("input.txt","r",stdin);
    int n;
    while(cin>>n)
    {
        cout<<sieve(n)<<"\n";
    }




	return 0;
}

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

C++: #include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int dp[1000005];
bool leap[1000005];
int main()
{
	#ifdef LOCAL
	freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
	#endif // LOCAL
	memset(leap,false,sizeof(leap));
	memset(dp,0,sizeof(dp));
    for(ll i = 2;i <= 999999;i++)
    {
        if(leap[i])continue;
        dp[i] = 1;
        for(ll j = i*i;j <= 999999;j = j + i)
            leap[j] = true;
    }
    for(int i = 1;i <= 999999;i++)dp[i] = dp[i] + dp[i - 1];
    int n;
    while(scanf("%d",&n) != EOF)
    {
        printf("%d\n",dp[n]);
    }
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define MAX_N 100001
int main(){
	int n;
	while(cin >> n){
		vector<int> vec;
		vector<int>::iterator it =vec.begin();
		for(int i=2;i<=n;i++){
			int flag=0;
			it =vec.begin();
			while(it!= vec.end()){
				if(i% *it==0){
					flag=1;
					break;
				}
				it++;
			}
			if(!flag)vec.push_back(i);
		}
		it =vec.begin();
		//while(it!= vec.end()){
		//	cout<<*it<<endl;
		//	it++;
		//}
		cout << vec.size()<<endl;
	}

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

int main(){
    vector<int> isprime;
    int n;
    cin >> n;
    for (int i = 0; i <= n; i++){
	isprime.push_back(1);
    }

    int prime = 0;
    for (int i = 2; i <= n; i++){
	if (isprime[i]){
	    prime++;
	    for (int j = 2; i * j <= n; j++) isprime[i*j] = 0;
	}
    }
    cout << prime << endl;
    
    return 0;
}

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

int a[999999];

int prime(int x) {
	if (a[x] == 1) return 1;
	else if (a[x] == 2) return 0;
	for (int i = 2; i < sqrt(x) + 1; i++) {
		if (x%i == 0) {
			a[x] = 2;
			return 0;
		}
	}
	return a[x]=1;
}
int main(){
	int n;
	while (scanf("%d", &n) != EOF){
		int count = 0;
		for (int i = 2; i <= n; i++) {
			if (prime(i))count++;
		}
		count++;
		if (n == 0)count = 0;
		if (n == 1)count = 0;
		if (n == 2)count = 1;
		printf("%d\n", count);
	}
	return 0;
}

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

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(scanf("%d", &n)!=EOF)
        printf("%d\n", prime[n]);
}

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

int main(){
  int input;
  while(scanf("%d",&input) != EOF){
    int count = 1;
    for(int i = 3;i <= input;i += 2){
      bool isPrime = false;
      for(int s = 3;s <= sqrt((float)i);s += 2){
        if(i % s == 0){isPrime = true; break;}
      }
      if(!isPrime)count++;
    }
    if(input == 2)printf("1\n");
    else if(input < 2)printf("0\n");
    else printf("%d\n",count);
  }

  return 0;
}

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

void sieve(int n, vector<int> &primes)
{
    vector<bool> v(n + 1, true);

    // check
    for (int i = 2, end = sqrt(n); i <= end; i++) {
        if (!i)
            continue;
        for (int j = i + i; j <= n; j += i)
            v[j] = false;
    }

    for (int i = 2; i <= n; i++)
         if (v[i])
            primes.push_back(i);
}

int main()
{
    vector<int> primes;
    vector<int> inputs;
    int i;

    // read all inputs
    for (int x; cin >> x;)
        inputs.push_back(x);

    // init sieve
    sieve(*max_element(inputs.begin(), inputs.end()), primes);

    for (auto x : inputs) {
        for (i = 0; i < primes.size(); i++) // find
            if (primes[i] == x) {
                i++;
                break;
            } else if (primes[i] > x)
                break;
        cout << i << endl;
    }

    return 0;
}