Go: package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}

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

void SieveOfEratosthenes(int n)
{
    int c = 0;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
       if (prime[p]){
            c++;
       }

       cout<<c<<endl;

}

// Driver Program to test above function
int main()
{
    int n;
    while(cin>>n)
    {
        SieveOfEratosthenes(n);
    }

    return 0;
}

C++: 
#include <iostream>
#include <cmath>
#include <vector>
#include <time.h>     // for clock()
using namespace std;

/*
1???2 ?????? n ?????§?????´??°???????????????
2??????????????£???????????°????????§???????°?????????????????????? p ??¨?????????????????????????????????????????°?????? p ??¨?????????
p ??\?????? p ????????°?????¨????¶????????????????
3???2??????????????°?????????????????????p ??? ???n ????¶??????????????????????????????????????????£?????????????´???°???
*/
// ??¨????????????????????????
int SieveOfEratosthenes(int num) {
	
	if (num < 2) {
		return 0;
	}
	// num???????´???°?????°
	int count = 0;
	int i = 2;
	while (i <= num) {
		if (i == 2) {
			count++;
			i++;
			continue;
		}
		else if (i % 2 == 0) {
			//count++;
			i++;
			continue;
		}
		else {
			// Route Num?????´??°??¨??????????????????
			int routeN_int = (int)sqrt(i);
			int j = 3;
			while (1) {
				if (j > routeN_int) {
					count++;
					break;
				}
				if (i % j == 0) {
					break;
				}
				j += 2;
			}
		}
		i++;
	}


	return count;
}

int main() {

	int num = 0;
	while (cin >> num, num != 0) {
		//clock_t start = clock();    // ??????????????????
		cout << SieveOfEratosthenes(num) << endl;
		//clock_t end = clock();     // ????????????
		//std::cout << "duration = " << (double)(end - start) / CLOCKS_PER_SEC << "sec.\n";
	}
	return 0;
}

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

bool IsPrime(int i){
    if(i < 2) return false;
    else if(i == 2) return true;
    else if(i % 2 == 0) return false;

    double sqrtNum = sqrt(i);
    for(int j = 3; j <= sqrtNum; j += 2){
        if(i % j == 0){
            return false;
        }
    }

    return true;
}

int main(){
    int n;
    while(cin >> n){
        int k = 0;
        for(int i = 0; i <= n; ++i){
           if(IsPrime(i) == true){
               k++;
           }else ;
        }
        cout << k << endl;
    }
}

C++: #include <iostream>

using namespace std;

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		//O(n)
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

//O(sqrt(n))
bool isPrime(int x) {
	if (x % 2 == 0)
		return true;
	for (int j = 3; j * j <= x; j += 2) {
		if (x % j == 0)
			return false;
	}
	return true;
}

//SÌÆµÄAO(n*sqrt(n))
//ÚÀÆµÄAOÌàÌ®ª1000ÈºÈçÜ¸ÔÉ¤A1­Â´¦éÆÜ¸ÔÉíÈ¢
//O(100*1000)=10­A

C++: #include<iostream>
using namespace std;
int main(){
	int n,i,j,k,l,sum=0,num,SUM=0;
	for(i=0;i<30;i++){
		cin>>n;
		for(j=1;j<=n;j++){
			for(k=j;k>=1;k--){
				num=j/k*k;
				if(num==j)sum++;
			}
			if(sum==2)SUM++;
			sum=0;
		}
		cout<<SUM<<endl;
		SUM=0;
	}
	return 0;
}

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

int main()
{
    bool *table = new bool[1000000];
    while (true) {
        int n;
        std::cin >> n;
        if (std::cin.eof()) break;

        memset(table, 1, sizeof(bool) * (n + 1));
        for (int i = 2; i * i <= n; ++i)
            for (int j = 2; i * j <= n; ++j)
                table[i * j] = false;

        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += table[i];
        std::cout << cnt << std::endl;
    }
    delete[] table;
}

C++: #include <iostream>
using namespace std;
int main(){
	int a[100001] = {0};
	for(int i = 0; i < 100001; i++){
		a[i] = 1;
	}
	a[0] = 0;
	a[1] = 0;
	for(int i = 0; i < 100; i++){
		if(a[i]){
			for(int j = i * 2; j < 100001; j += i){
				a[j] = 0;
			}
		}
	}

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

	return 0;
}

C++: #include<stdio.h>

int s[1000000] = {0};

int main(){
	int a,b,c,d,e;
	int temp;
	int cont = 0;
	
	while(scanf("%d",&a) != EOF){
		/*
		for(int i = 0; i < a; i++){
			s[i] = 1;
		}
		*/
		
		cont = 0;
		
		s[0] = 1;
		s[1] = 1;
		
		for(temp = 2; temp < a+1; temp++){
			if(s[temp] == 0){
				for(b=temp; b <= a; b+= temp){
					if(b == temp){
						s[b] = 0;
					}
					else{
						s[b] = 1;
					}
				}
			}
		}
		
		for(c = 0; c < a+1; c++){
			if(s[c] == 0){
				
	//		printf("%d\n",c);
				cont++;
			}
		}
		
		printf("%d\n",cont);
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	int x = 1000000;
	int p[x],q[x];
	for(int i=2;i<x;i++) p[i] = 0;
	for(int i=2;i<x;i++){
		if(q[i]==0) for(int j=2;j<x/i;j++) q[i*j] = 1;
	}
	int c = 0;
	for(int i=2;i<x;i++) if(q[i]==0) p[c++] = i;
	int n;
	while(cin >> n){
		int a = 0;
		for(int i=0;i<c-1;i++){
			if(p[i]>a) break;
			a++;
		}
		cout << a << endl;
	}
}

C++: #include <iostream>
#include <map>
using namespace std;
#define MAX_N 999999
int main()
{
    int n;
    bool notPrime[MAX_N+2];
    int count[MAX_N+2];
    for (int i = 2 ; i <= MAX_N ; i++)
    {
        if (!notPrime[i])
        {
            for (int g = i+i ; g <= MAX_N ; g += i)
            {
                notPrime[g] = true;
            }
        }
    }
    int cnt = 0;
    count[1] = 0;
    for (int g = 2 ; g <= MAX_N ; g++)
    {
        if (!notPrime[g])
            cnt ++;
        count[g] = cnt;
    }
    for(int n;cin>>n;n++){
        cout<<count[n]<<endl;
    }
    
}

C++: #include <iostream>

using namespace std;

#define MAX 1000000

int main(){
  int n;
  bool p[MAX];
  p[0] = false;
  p[1] = true;
  for(int i=2;i<MAX;i++)p[i] = true;
  for(int i=2; i*i<MAX;i++){
	if(p[i]){
	  for(int j=i*i;j<MAX;j=j+i){
		p[j] = false;
	  }
	}
  }
  
  while(cin >> n){
	int cnt = 0;
	for(int i = 0;i<n;i++){
	  if(p[i]) cnt++;
	}
	cout << cnt << endl;
  }
  
  return 0;
}

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

int main(){

  int n;
  int a,i,count;
  while(cin >> n){
    if(n < 1000000){
      count = 0;
      for(;1<n;n--){
	for(a=2,i=1;a<=n/2;a++)
	  if(n%a == 0){
	    i = 0;
	    break;
	  }
	if(i)
	  count++;
      }
      cout << count << endl;
    }
  }
  return 0;
}

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

int main()
{
	int n = 0, x = 0;
	int countdata[1000];
	while (cin >> n) {
		int count = 0;
		for (int a = 2; a <= n; a++) {
			int count2 = 0;
			if (a % 2 != 0 && a % 3 != 0 && a % 5 != 0 && a % 7 != 0) {
				count++;
			}
			else {
				for (int b = 2; b <= a / 2; b++) {
					if (a%b != 0)
						count2++;
				}
				if (count2 == a / 2 - 1)
					count++;
			}
		}
		countdata[x] = count;
		x++;
	}
	for (int a = 0; a < x; a++) {
		cout << countdata[a] << endl;
	}
}