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<iostream>
using namespace std;
int main(){
	int n, cnt;
	
	while(cin >> n){
		bool prime[1000000] = {false};
		prime[1] = true; //1???????????\
		
		// ??¨??????????????????????????????
		for(int j = 2; j*j <= n; j++){
			if(prime[j] == false){
				for(int k = j; k*j <= n; k++){
					prime[j*k] =true;
				}
			}
		}
		cnt = 0;
		for(int i = 1; i <= n; i++){
			if(prime[i] == false) cnt++;
		}
		
		cout << cnt << endl;
	}
}

C++: #include<cstdio>
using namespace std;
bool us[1000010]={false};
int p[1000010] = {0};
int main(){
    /*Eratosthenes*/
    p[0] = 2;
    for(int i = 0; i <= 1000010; i+=2){
        us[i] = true;
    }
     
    int cnt = 1;
    for(int i = 3; i <= 1000010; i+=2){
        int q = 0;
        if(us[i] == true)continue;
        else if(us[i] == false){
            p[cnt] = i;
            cnt++;
            us[i] = true;
            q = i;
            for(int j = q+q; j <= 1000010; j += q){
                us[j] = true;
            }
        }
    }
     
    int n;
    while(~scanf("%d",&n)){
        int x = 0;
        while(1){
            if(p[x] > n)break;
            x++;
        }
        printf("%d\n",x);
    }
    return 0;
}

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

int main()
{
	int count=1,n,flag;
	
	while(cin>>n)
	{
		if(n<=1) 
		{
			cout<<0<<endl;
		}

		else{
		for(int i=3;i<=n;i+=2)
		{
			flag=1;
			for(int j=3;j<=sqrt(i);j+=2)
				if(i%j==0)
				{
					flag=0;
					break;
				}
			if(flag==1)
				count++;
		}
		printf("%d\n",count);
		count=1;}
	}
}

C++: #include<stdio.h>
int main()
{
    long long n;
    while(scanf("%lld",&n)==1)
    {
       long long i,j,k,s=0;
       for(i=2;i<=n;i++)
    {
        k=0;
      for(j=2;j*j<=i;j++)
      {
          if(i%j==0)
          {
              k=1;
              break;
          }
      }
       if(k==0)
          {
             ++s;
          }
    }
        printf("%lld\n",s);
    }
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>

static int GetPrimeNumberNum(int maxValue);

int main(void)
{
  int n;
  
  while (std::cin >> n) {
    std::cout << GetPrimeNumberNum(n) << std::endl;
  }
}

static int GetPrimeNumberNum(int maxValue)
{
  std::vector<int> searchList;
  std::vector<int> primeList;
  
  for (int i = 2; i <= maxValue; i++) {
    searchList.push_back(i);
  }
  
  double maxValueSq = sqrt((double)maxValue);
  
  while (true) {
    int newPrime = searchList.at(0);
    
    if (newPrime > maxValueSq) {
      break;
    }
    
    primeList.push_back(newPrime);
    
    for (std::vector<int>::iterator it = searchList.begin();
         it != searchList.end();
         ) {
      if (*it % newPrime == 0) {
        it = searchList.erase(it);
      }
      else {
        ++it;
      }
    }
  }
  
  for (std::vector<int>::iterator it = searchList.begin();
       it != searchList.end();
       ++it) {
    primeList.push_back(*it);
  }
  
  searchList.clear();
  
  return primeList.size();
}

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

int main(){
   bool is_prime[1000000];
   is_prime[0]=is_prime[1]=false;
   for(int i=2;i<1000000;i++)
      is_prime[i]=true;
   for(int i=2;i*i<1000000;i++){
      if(is_prime[i]){
         for(int j=i*i;j<1000000;j+=i){
            is_prime[j]=false;
         }
      }
   }
   int n[1000000];
   int count=0;
   for(int i=0;i<1000000;i++){
      if(is_prime[i])
         count++;
      n[i]=count;
   }
   while(true){
      int x;
      cin >> x;
      if(cin.eof())
         break;
      cout << n[x] << endl;
   }
   
   return 0;
}

C++: #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int up=1000*1000;
int n[up];
bool comp[up];
int main() {
	int r=0;
	for(LL i=2;i<up;i++){
		if(comp[i]==false){
			r++;
			for(LL j=i*i;j<up;j+=i){
				comp[j]=true;
			}
		}
		n[i]=r;
	}
	int k;
	while(cin >> k)
	{
		cout << n[k] << endl;
	}
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt;
    int list[100000];

    cnt=0;
    for (long i=2; i<1000000; i++){
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
	printf("input : ");
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (long i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

inline int IsPrime(int n){
    int i;

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

C++: #include<iostream>

using namespace std;

int main(){
    static bool not_prim[1000000];
    static int num_prim[1000000];
    for(int i=2;i<1000000;i++)
    {
        if(!not_prim[i])
        {
            for(int j=2;j*i<1000000;j++)
            {
                not_prim[i*j]=true;
            }
        }
        num_prim[i]=num_prim[i-1]+!not_prim[i];
    }
    int n;
    while(cin >> n){
    cout<<num_prim[n]<<endl;
    }
    return 0;
}

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

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		std::vector<int> num;
		int max=2;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(unsigned int i=0;i<count;i++){
				if(m!=num[i] && m%num[i]==0){
					check=false;
					if(max<m){
						max=m;
					}
					break;
				}
			}
			if(check==true){
				if(count>0){
					if(max>num[count-1]){
						for(int i=max+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
					else{
						for(int i=num[count-1]+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
				}
				else{
					for(int i=2;i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							if(max<m){
								max=m;
							}
							break;
						}
					}
				}
			}
			if(check==true){
				num.push_back(m);
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;
	int *k;
	
	while (cin >> n) {
		int counter = 0;
		k = (int *)malloc(sizeof(int) * n);
		if (k == NULL) {
			exit(0);
		}
		k[0] = 1;
		for (int i = 1; i < n; i++) {
			k[i] = 0;
		}

		for (int i = 1; i < n; i++) {
			if (k[i] == 0) {
				for (int j = 1; j < i; j++) {
					if (k[j] == 0) {
						if ((i+1) % (j+1) == 0) {
							k[i] = 1;
							break;
						}
					}
				}
				if (k[i] == 0) {
					for (int t = 2; t < n/(i+1); t++) {
						k[(i+1)*t-1] = 1;
					}
				}
			}
		}

		for (int i = 0; i < n; i++) {
			if (k[i] == 0) {
				counter++;
			}
		}

		cout << counter << endl;

		free(k);
	}

	return 0;
}