Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

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

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

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

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt((double)MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

	while( cin >> n ){		
		ans = 0;
		for(int i=0 ; i<=n ; i++){
			if(p[i]){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

C++: #include <cstdio>
#define max_n 999999
#define INF 1000000
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        prime[i] = INF;
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        //printf("%d\n",n);
        int ans = 0;
        for(int i =0; i<max_n; i++){
            if(prime[i]>n){
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

int main() {
  constexpr int max = 1000000;
  vector<bool> isPrime(max, true);
  isPrime[0] = isPrime[1] = false;
  for (int i = 2; i * i < max; i++) {
    if (isPrime[i]) {
      for (int j = i * 2; j < max; j += i) {
        isPrime[j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << 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 = 1;
		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j * j <= i; j += 2){
				if(i % j == 0){
					flag = true;
					break;
				}
			}
			if(flag != true){
				count++;
			}
			else{
				flag = false;
			}
		}
		cout << count << endl;
	}

	return 0;
}

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;
    
}