Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <iostream>
using namespace std;
int main()
{
	int prime[80000];
	int ptr=2;
	prime[0] = 2;
	prime[1] = 3;
	for(int num=5; num<1000000; num+=2){
		bool f = false;
		for(int i = 0; i<ptr; i++){
			if (prime[i]*prime[i] > num) break;
			if (num%prime[i]==0) {
				f = true;
				break;
			}
		}
		if(!f) prime[ptr++] = num;
	}
	int n;
	while(cin >> n){
		int k=0;
		for(;prime[k]<=n;k++);
		cout << k << endl;
	}
	return 0;
}

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

using namespace std;

int main(void){
  int n;
  while(cin >> n){
    if(n==1){
      printf("%d\n",0);
      break;
    }
    int p[100000];
    p[0]=2;
    int pi=1;
    int i=2;
    while(i<=n){
      int t=1;
      int j;
      for(j=0;j<pi;j++){
	if(i%p[j]==0){
	  t=0;
	  break;
	}
      }
      if(t==1){
	p[pi]=i;
	pi++;
      }
      i++;
    }
    printf("%d\n",pi);
  }
  return 0;
}

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

class SOSU{
   public:
      int sosu(int);
};
int SOSU::sosu(int n){
   if(n==2)
      return 1;
   
   int i,j,z=1,flag;
   int ans = 1;
   int s[9999];
   s[0]=2;
   for(i=3;i<=n;i++){
      flag = 0;
      for(j=0;j<z;j++){
         if(i%s[j]==0){
            flag++;
            break;
         }
      }
      if(flag == 0){
         s[z] = i;
         z++;
         ans++;
      }
   }
   return ans;
}
int main(){
   SOSU Sosu;
   int n,ans;
   while(cin>>n){
      ans = Sosu.sosu(n);
      printf("%d\n",ans);
   }
   return 0;
}

C++: #include<iostream>
using namespace  std;
int primes[1000010];
bool isPrime(int p)
{
	bool flag = true;
	for (int i = 2; i * i <= p; i++)
	{
		if (p % i == 0)
		{
			flag = false;
			break;
		}
	}
	return flag;
}
int main()
{
	int n;
	for (int i = 0; i <= 999999; i++)primes[i] = 0;
	for (int i = 2; i <= 999999; i++)if (isPrime(i))primes[i] = 1;
	for (int i = 0; i <= 999999; i++)primes[i + 1] += primes[i];
	while (cin >> n)cout << primes[n] << endl;
	return 0;
}

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