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 <memory.h>
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int i;
	int pos;
	int val;
	int target;
	int sosuList[78499];

	memset(sosuList, 0, sizeof(sosuList));

	sosuList[0] = 2;
	sosuList[1] = 3;
	sosuList[2] = 5;
	sosuList[3] = 7;
	sosuList[4] = 11;

	while (cin >> target) {
		for (pos = 0; sosuList[pos] != 0; pos++) {
			if (sosuList[pos] > target) break;
		}
		for (val = sosuList[pos - 1] + 1 ; val <= target ; val++) {
			for (i = 0; i < pos - 1 ; i++) {
				if (sosuList[i] * 2 > val) { i = pos; break; }
				if (val % sosuList[i] == 0) break;
			}
			if (i >= pos - 1) sosuList[pos++] = val;
		}
		cout << pos << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

bool isprime[1000000];

void solve(int n) {
    int cnt = 0;
    for (int i = 2; i <= n ; ++i) {
        if(isprime[i]) {
            cnt++;
            for (int j = i*2; j <=n ; j = j + i) {
                isprime[j] = false;
            }
        }
    }
    cout << cnt << endl;
}

int main() {
    int n;
    while(cin>>n) {
        for (int i = 0; i <= n; ++i) {
            isprime[i] = true;
        }
        isprime[0] = isprime[1] = false;
        solve(n);
    }


    return 0;
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int list[100000];

    cnt=0;
    for (long i=2; i<1000000; i++){
	//    printf("%d %d\n",i, cnt);
        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;
}

int IsPrime(int n){
    int i;

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

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

int main()
{
	int n;
	const int MAX = 1000000;
	int primecount[MAX];

	for (int i = 2; i < MAX; i++) {
		primecount[i] = 1;
	}

	for (int i = 2; i < MAX; i++) {
		if (primecount[i] == 1) {
			for (int j = i * 2; i < MAX; j += i) {
				primecount[j] = 0;
			}
		}
	}

	for (int i = 1; i < MAX; i++) {
		primecount[i] += primecount[i - 1];
	}

	short i = 1;

	while (cin >> n && i <= 30) {
		cout << primecount[n] << endl;
		i++;
	}

	return 0;
}

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

int main(){
	const int max_num=1100000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[168]={2 ,3 ,5 ,7 ,11 ,13 ,17 ,19 ,23 ,29 ,31 ,37 ,41 ,43 ,47 ,53 ,59 ,61 ,67 ,71 ,73 ,79 ,83 ,89 ,97 ,101 ,103 ,107 ,109 ,113 ,127 ,131 ,137 ,139 ,149 ,151 ,157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233 ,239 ,241 ,251 ,257 ,263 ,269 ,271 ,277 ,281 ,283 ,293 ,307 ,311 ,313 ,317 ,331 ,337 ,347 ,349 ,353 ,359 ,367 ,373 ,379 ,383 ,389 ,397 ,401 ,409 ,419 ,421 ,431 ,433 ,439 ,443 ,449 ,457 ,461 ,463 ,467 ,479 ,487 ,491 ,499 ,503 ,509 ,521 ,523 ,541 ,547 ,557 ,563 ,569 ,571 ,577 ,587 ,593 ,599 ,601 ,607 ,613 ,617 ,619 ,631 ,641 ,643 ,647 ,653 ,659 ,661 ,673 ,677 ,683 ,691 ,701 ,709 ,719 ,727 ,733 ,739 ,743 ,751 ,757 ,761 ,769 ,773 ,787 ,797 ,809 ,811 ,821 ,823 ,827 ,829 ,839 ,853 ,857 ,859 ,863 ,877 ,881 ,883 ,887 ,907 ,911 ,919 ,929 ,937 ,941 ,947 ,953 ,967 ,971 ,977 ,983 ,991 ,997 };
	int sosuu=0;
	int k=168;

	for(int i=0;i<168;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1001;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<168;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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

int main()
{
	bool prm[N];
	for(int i=0; i<N; i++)
	{
		prm[i]=true;
		int upto= (int) sqrt(N);
		for(int i=2;i<= upto; i++)
		{
			if(prm[i])
				for(int j=2; j*i<N; j++)
				{
				    prm[i*j]=false;
				}
		}
		int n;
		while(cin>>n)
		{
			int count=0;
			for(int i=2; i<=n; i++)
			{
				if(prm[i])
					count++;
			}
			cout<<count<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;


using namespace std;
bool priN[1000000]={};
bool pri[1000000]={};

bool isPrime(int n){
	if(priN[n]==true)return pri[n];
	for(int i=3;i<=sqrt((double)n);i++){
		if(n%i==0){
			priN[n]=true;
			pri[n]=false;
			return false;
		}
	}
	priN[n]=true;
	pri[n]=true;
	return true;
}

int main(){
	while(1){
		int n;
		if( !(cin>>n) )break;
		ll sum=1;
		if (n<2) sum--;
		for(int i=3;i<=n;i+=2){
			if(isPrime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {

	int n,count;

	while (cin >> n) {
		count = 0;
		
		//?´???°????????????????¨???¶?????????????????????????¢????
		bool *is_prime;
		is_prime = (bool *)malloc(n+1);
		if (is_prime == NULL) {
			cout << "malloc error" << endl;
			break;
		}

		//????????¨????´???°??§????????¨??????
		for (int i = 0; i <= n; i++) {
			is_prime[i] = true;
		}

		for (int i = 2; i <= sqrt(n); i++) {
			//?´???°???????????§????????£???????????????????????§??????
			if (is_prime[i] == true) {
				//????????°???????????§????????°????????£?????????
				for (int j = i+1; j <= n; j++) {
					//cout << "i=" << i << " j=" << j << " is_prime(i)=" << is_prime[i] << " is_prime(j)=" << is_prime[j] << endl;
					if (is_prime[j] == true) {
						if (j%i == 0) {
							//????????????????????????????´???°??§?????????
							is_prime[j] = false;
						}
					}
				}
			}
		}

		//?´???°??¨?¢????????????°????????°????????????
		for (int i = 2; i <= n; i++) {
			if (is_prime[i] == true) {
				count++;
				//cout << " " << i;
			}
		}

		//??¨???
		cout << count << endl;
	}
	return 0;
}

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

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt(a);
      for(i=2; i<=a_sqrt; i++){
        for(j=past+1; j<=a; j++){
          if(j%i==0) chk[j]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int PrimeNum(int n){
  for(int i = 2;i <= n;i++){
    if(i == n){
      return 1;
    }
    if(n % i == 0){
      return 0;
    }
  }
}
int main(){
  int n,num;
  for(cin >> n; ;cin >> n){
    num = 0;
     for(int k = 2;k <= n;k++){
       if(PrimeNum(k) == 1){
	 num = num +1;
       } 
     }
     cout << num;
  }
}