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++: //求n以内素数个数以及所有素数
//复杂度O(n*loglogn)
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
const int MAXN = 1000000+5;

int prime[MAXN]; //第i个素数
bool is_prime[MAXN+1]; //is_prime[i]为true表示i是素数，否则不是

//返回n以内素数个数
int seive(int n){
    int p=0;
    for(int i=0;i<=n;++i) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    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]=false;
        }
    }
    return p;
}

bool is_prime_large[MAXN]; // is_prime_large[i-a]=true <--> i是素数
//求区间[a,b)之间的素数及个数, a<b<=10^12, b-a<=10^6
int segment_sieve(ll a, ll b){
    seive((int)sqrt(b)+1);
    for(int i=0;i<b-a;++i) is_prime_large[i]=true;

    for(int i=2;(ll)i*i<b;++i){
        if(is_prime[i]){
            for(ll j=max(2LL,(a+i-1)/i)*i; j<b; j+=i) is_prime_large[j-a]=false;
        }
    }

    int p=0;
    for(ll i=a;i<b;++i){
        if(is_prime_large[i-a]) p++; 
    }
    return p;
}

int main(){
/*    ll a=22801763489, b=22801787297;*/
    //int p=segment_sieve(a,b);
    //cout<<"segment_sieve:"<<p<<endl;

    int n;
    while(cin>>n) {
        cout<<seive(n)<<endl;
    }
}

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

#define MAX 1000000

int main(){
	int i,j,k;
	bool n[MAX];
		i=MAX; while(i--) n[i]=true;

	while(~scanf("%d", &i)){

	for(j=2; j<i; j++){
		if(n[j]==true){
		for(k=2; j*k<i; k++){
			n[j*k]=false;
		
		}
		}
	}

	for(j=2, k=0; j<i; j++) if(n[j]==true) k++;

	printf("%d\n", k);
	}
 return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
  long n;
  while (cin >> n) {
    if (n == 1) {
      cout << 0 << endl;
      continue;
    }
    int x = 1;
    if (n == 2) {
      cout << x << endl;
      continue;
    }
    x++;
    for (int i = 3; i <= n; i += 2)
      for (int j = 2; j * j <= i; j++) {
        if (i % j == 0) break;
        if ((j + 1) * (j + 1) > i) x++;
      }
    cout << x << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int max = 1000100;
	bool prime[1000100];
	int dp[1000100];
	prime[0] = prime[1] = false;
	int ret=0;
	memset(prime,true,sizeof(prime));
	memset(dp,0,sizeof(dp));
	int hako[30];
	memset(hako,0,sizeof(hako));
	REP(i,30) cin >> hako[i];
	for(int i=2;i<sqrt(max);i++)for(int j=i*2;j<max;j=j+i){
		prime[j] = false;
	}
	for(int i=1; i<max ;i++){
		dp[i]=dp[i-1];
		if(prime[i])dp[i]++;
	}
	REP(i,30)	cout << dp[hako[i]] << endl;
	return 0;
}

C++: #include<iostream>
#define N 1000000
using namespace std;
void PrimeNum(int n,bool Primeif[]){
  for(int i = 2;i*i < n;i++){
    if(Primeif[i] == true){
      for(int k = 2;k * i < n;k++){
	Primeif[k*i] = false;
}
    }
  }
}
int main(){
  int n,num;
  bool Primeif[N+1];
  Primeif[1] = false;
  for(int i = 2;i < N;i++){
    Primeif[i] = true;
  }
  PrimeNum(N+1,Primeif);
  
  while(cin >> n){
    num = 0;
    for(int i = 0;i <= n;i++){
      if(Primeif[i] == true){
	num = num+1;
      }
    }
     cout << num << endl;
     
   } 
    
}

C++: #include <bits/stdc++.h>

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

    int n;
    while (~scanf("%d", &n)) {
        for (int i = 2; i * i <= n; ++i) {
            if (a[i]) for (int j = i + i; j <= n; j += i) a[j] = false;
        }
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

C++: #include <stdio.h>
#include<math.h>
int main()
{
    long long int n,m,i,j,k,l,a[1000000];
    for(i=0;i<100000;i++)
    {
        a[i]=i+1;
    }

    m=sqrt(1000000);

    for(i=2;i<=m;i++)
    {
        for(j=i+1;j<=1000000;j++)
        {
            if(a[j]%i==0) a[j]=0;
        }
    }

    while(scanf("%lld",&n)!=EOF)
    {
        k=0;
        for(i=0;i<n;i++)
        {
            if(a[i]==0)
            {

            }
            else
            {
                k++;
            }
        }
        printf("%lld\n",k-1);
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long lon
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number[40] = {0};
    int answer[40] = {0};
    int i = 0,j = 0,k = 0;
    while(cin >> number[i], i != 30)
    {
        for(k = number[i]; k>1;k--)
            for(int l = k-1;l>0;l--)
            {
                if(k == 2 && l == 1)
                {
                    answer[i]++;
                    break;
                }
                if(k % l == 0)
                    break;
                if(l == 2)
                {
                    answer[i]++;
                }

            }
        i++;
    }
    REP(j,i)
    cout << answer[j]<< endl;
    return 0;
    
}

C++: #ifndef HEADER_H
#define HEADER_H
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<ctype.h>
#include<cstdlib>
#include<cmath>

#define F(t,i,s,r) for(t i=s;i<r;i++)
#define FE(t,i,s,r) for(t i=s;i<=r;i++)
#define R(t,i,s,r) for(t i=s;i>r;i--)
#define RE(t,i,s,r) for(t i=s;i>=r;i--)

using namespace std;
//freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
#endif
#define ll long long
vector<bool>isprime;
void seiveAtkin (ll n) {
	isprime.resize (n + 1, false);
	isprime[2] = true, isprime[3] = true;
	ll lim = ceil (sqrt (n)), num;
	FE (ll, x, 1, lim) {
		FE (ll, y, 1, lim) {
			num = 4 * x*x + y*y;
			if (num <= n && (num % 12 == 1 || num % 12 == 5)) {
				isprime[num] = true;
			}
			num = 3 * x*x + y*y;
			if (num <= n && num % 12 == 7) {
				isprime[num] = true;
			}
			if (x > y) {
				num = 3 * x*x - y*y;
				if (num <= n && num % 12 == 11) {
					isprime[num] = true;
				}
			}
		}

	}
	FE (ll, i, 5, lim) {
		if (isprime[i]) {
			for (ll j = i*i; j <= n; j += i) {
				isprime[j] = false;
			}
		}
	}
}
int main () {
	int n;
	seiveAtkin (999999);
	vector<int>count;
	count.resize (1000000, 0);
	FE (int, i, 1, 999999) {
		count[i] += count[i - 1];
		if (isprime[i]) {
			count[i]++;
		}
	}
	while (cin>>n)
	{
		cout<<	count[n]<<endl;
	}
}