Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var primeCount int
	for sc.Scan() {
		input := nextInt()
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		fmt.Printf("%d\n", primeCount)
		primeCount = 0
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2 || num == 5:
		return true
	case num < 2 || num%2 == 0 || num%5 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int,int>;
using ppa = pair<pa,int>;
#define SORT(v, n) sort(v, v+n);
#define ALL(v) v.begin(),v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v),greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)),v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i = (b-1); i >= a; i--)
#define rrep(i,n) RFOR(i,0,n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a,b) a = min(a,b)
#define maxs(a,b) a = max(a,b)

//4??????
//int dy[]={0, 1, 0, -1};
//int dx[]={1, 0, -1, 0};

//8??????
//int dy[]={0,0,1,-1,1,1,-1,-1};
//int dx[]={1,-1,0,0,1,-1,1,-1};

const ll MOD = 1000000007;

ll pow_mod(ll a,ll b,ll mod){
    ll tmp = 1;
    a %= mod;
    if(b > 0){
        tmp = pow_mod(a, b/2, mod);
        if(b % 2) tmp = (((tmp*tmp)%mod)*a)%mod;
        else tmp = (tmp*tmp)%mod;
    }
    return tmp;
}

int mm = 999999+1;
vector<bool> d(mm,true);

void hoge(){ FOR(i,2,mm) for(int j = 2; i*j <= mm; j++) d[i*j] = false; }

void solve() {
    vector<int> dp(mm,INF);
    int val;
    int m = 2;
    dp[m] = 1;
    d[0] = d[1] = dp[0] = dp[1] = 0;
    hoge();
    while(cin >> val){
        if(dp[val] == INF){
            FOR(i,m+1,val+1){
                dp[i] = dp[i-1] + (d[i] ? 1 : 0);
            }

            m = val;
        }
        cout << dp[val] << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    solve();

    return 0;
}

C++: #include <stdio.h>
#include<iostream>
#include <math.h>
using namespace std;
int main() {
        int n;
        int data=0;
        while(scanf("%d",&n)!=EOF&&data<=30){
            int a[n];
            int num=0;
            for(int i=0; i<=n; i++) {
                a[i] = i;
            }
            a[1] = 0;
            for (int i=2; i<sqrt(n); i++) {
                for (int j=i+1; j<=n; j++) {
                        if (a[j]!=0 && a[j]%i==0) {
                                a[j] = 0;
                        }
                }
            }
            for(int i=2;i<=n;i++)
                if(a[i]!=0)
                    num++;
            cout<<num<<endl;
            data++;
        }
        return 0;
}

C++: #include<iostream>
#include<cassert>
#include<time.h>
#include<cmath>
using namespace std;

/**
作用：判断一个数是否是素数
参数x：待判断的素
参会primes：存储比x小的所有素数 的数组
返回：是素数返回true，否则返回false
*/
bool isPrime(int x,int *primes)
{
    for(int i=0;primes[i]*primes[i]<=x;++i) //用primes中存储的素数做为试除因子。
    {
        if(x%primes[i]==0) return false;
    }
    return true;
}


/**
作用：统计[2,n]之间的素数的个数
参数：n
返回：素数的个数
*/
int countPrimes(int n) {
    
    if(n<2) return 0;
    
    int count=0;
    int* primes = new int[(n-1)/2+1] ;
    
    if(n >=2) primes[count++] = 2;   //2是第一个素数，直接将他放入数组。

    for(int i=3;i<=n;++i)
    {
        if(isPrime(i,primes))   //如果 i为素数
        {
            primes[count++] = i; //则将 i存储到数组中
        }
    }

    delete[] primes;
    return count;

}

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

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

int sosu( int n ) {
	int i , lim = (int)(sqrt(n));
	
	if ( n == 2 ) return 1;
	if ( n % 2 == 0 ) return 0;
	
	for ( i = 3; i <= lim; i+=2 ) {
		if ( n % i == 0 ) return 0;
	}
	return 1;
}

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

C++: #include<iostream>
using namespace std;
bool F(int n)
{
	bool r=true;
	for(int i=2;i<n;i++)
	{
		if(n%i==0){
			r=false;
			break;
		}
	
	}	
	return r;
}

int main()
{
	int number=0;
	int result=0;
	while(1)
	{
		result=0;
		cin>>number;
		for(int i=number;i>=2;i--)
		{
			if(F(i)==true)
				result++;
		}
		cout << result <<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAX_N = 10000000, sqrt_N = 1000;
bool prime[MAX_N];
int wei[1000000];

int main()
{
  int N, i, j, k;

  for (i = 1; i <= 5; i += 4){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 4 * k * k + j * j) <= N; ++k){
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 2; i <= 4; i += 2){
    for (j = i; j <= sqrt_N; j += 6){
      for (k = 1; k <= sqrt_N && (N = 3 * k * k + j * j) <= N; k += 2){
        prime[N] = !prime[N];
      }
      for (k = j + 1; k <= sqrt_N && (N = 3 * k * k - j * j) <= N; k += 2){
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 3; i <= sqrt_N; i += 6){
    for (j = 1; j <= 2; ++j){
      for (k = j; k <= sqrt_N && (N = 4 * k * k + i * i) <= N; k += 3){
        prime[N] = !prime[N];
      }
    }
  }
  for (i = 5; i <= sqrt_N; ++i){
    if (prime[i]){
      for (j = i * i; j <= N; j += i * i){
        prime[j] = false;
      }
    }
  }
  prime[2] = prime[3] = true;

  for (i = 2; i < 1000000; ++i){
    wei[i] += wei[i - 1];
    if (prime[i]) wei[i]++;
  }

  while (cin >> N) cout << wei[N] << '\n';
  return 0;
}

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

typedef long long LL;
using namespace std;

const int X = 1000001;
bool Find[X];

void init(){
  for(int i=0;i<X;i++){
    Find[i] = false;
  }
  for(int i=2;i<=sqrt(X);i++){
    if(Find[i])continue;
    for(int j=i+1;j<X;j++){
      if(Find[j])continue;
      if(j%i==0)Find[j]=true;
    }
  }
}

int main(){
  init();
  int n;
  while(cin >> n){
    int answer = 0;
    for(int i=2;i<n+1;i++){
      cout << Find[i] <<endl;
      if(!Find[i])answer++;
    }
    cout << answer << endl;
  }
  return 0;
}

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

int is_prime(int n){
    int i;
    int flag = 0;
    for(i=2; i<n; i++){
        if(n%i==0) { flag=1; break; }
    }
    return (flag==1)?0:1;
}


int main(){
	int i, j, n, num = 0, count = 0;

	while(cin >> n){
		count = 0;
		for(i = 1; i <= n; i++){
			if(is_prime(i) == 1 && i != 1) count ++;
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;

int main(){
  int n;
  while(cin >> n){
    int ans=0;
    vector<int> vec;
    vec.emplace_back(2);
    for(int i = 3; i<=n; i+=2){
      bool isPrimeN = true;
      for(int j=3; j<=floor(sqrt(i)); j++){
        if(i%j==0){
          isPrimeN = false;
          break;
        }
      }
      if(isPrimeN){
        vec.emplace_back(i);
      }
    }
    cout << vec.size() << endl;;
  }
  return 0;
}