Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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


int num[1000001]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=1000000;i++)
	num[i]=1;
for(int i=2;i<=1000000;i+=2){
for(int k=2;k<=sqrt((double)i);k+=2){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

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

const int ARR_MAX = 1000000;
int fl[ARR_MAX];
int sm[ARR_MAX+1] = {0};

void init_arr();
void isfl(int);

int main(void) {
  int tag;
  init_arr();

  while(!cin.eof()){
    cin >> tag;
    if(tag == 0) break;
    isfl(tag);
    cout << sm[tag] << endl;
  }
  return 0;
}

void init_arr(){
  for(int i=0;i<ARR_MAX;i++) fl[i] = 1;
}

void isfl(int tag){
  int i,lim,idx = 2;
  fl[0] = 0;
  fl[1] = 0;

  lim = sqrt(tag);

  while(idx <= lim){
    if(fl[idx] == 1) for(i = idx*2;i<=tag;i+=idx) fl[i] = 0;
    idx++;

  }
  for(int i = 2;i<=tag;i++) sm[i] = sm[i-1] + fl[i];
  return;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[30];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num <30; data_num++)
	{
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0)
			break;
	}

	for (k = 0; k < data_num; k++)
	{

		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);

		prime[0] = 0;
		for (i = 1; i < data[k]; i++)
		{
			prime[i] = 1;
		}

		for (i = 1; i < sq_num; i++)
		{

			if (prime[i] == i)
			{
				for (j = (i + 1); (i + 1)* j <= data[k]; j++)
				{
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0; 
		for (i = 0; i < data[k]; i++)
		{
			if (prime[i] == 1)
			{
				cnt++;
			}
		}
		printf("%d\n", cnt-1);
		free(prime);
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N;
//??¨????????????????????????
bool is_prime[ 999999 + 1 ];
int E( const int N )
{
    int cnt{};
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//?????????
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            cnt++;
        }
    }
    return cnt;
}
int main()
{
    while( cin >> N )
    {
        cout << E( N ) << endl;
    }
    return 0;
}

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_prime[1000000];
  int cnt=0;

  for(int i=0; i<1000000; i++){
    if(is_prime[i]){
      cnt++;
    }
    n_prime[i]=cnt;
  }

  while(true){
    int n;
    cin >> n;

    if(cin.eof())
      break;

    cout << n_prime[n] << endl;
  }

  return 0;
}

C++: #include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    int n,ans=0;
    scanf("%d",&n);
    vector<bool> tab(n+1,true);
    int upto=sqrt(n);
    for(int i=2;i<=upto;i++){
        if(tab[i]){
            for(int j=i*2;j<=n;j+=i){
                tab[j]=false;
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(tab[i]) ans++;
    }
    printf("%d\n",ans);
}

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

int main(){
	int a[1000000]{};
	bool b[1000000]{};
	a[1]=0;
	int s=0;
	for(int c=2;c<1000000;c++){
		if(b[c]==false){
			s++;
			for(int d=c*2;d<1000000;d+=c)b[d]=true;
		}
		a[c]=s;
	}
	int k;
	while(cin>>k){
	printf("%d\n",a[k]);	
	}}

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

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

int main()
{
    int i,n,t,c,k;
    while(scanf("%d",&t)==1)
    {
        for(k=0;k<t;k++)
        {
            c=0;
            scanf("%d",&n);

            for(int j=2;j<=n;j++)
            {
                i=prime(j);
                if(i==1)
                c++;
            }

            printf("%d\n",c);
        }

    }

    return 0;
}

C++: #include<iostream>

using namespace std;

const int MAX_N = 1000000;
bool isprime[MAX_N];

void init() {
    fill(isprime,isprime+MAX_N,true);
    isprime[0] = isprime[1] = false;
    for (int i = 2; i < MAX_N; i++) {
        if (isprime[i]) {
            for (int k = 2; i * k < MAX_N; k++) {
                isprime[i * k] = false;
            }
        }
    }
}

int nprimes(int n) {
    int res = 0;
    for (int i = 0; i <= n; i++) {
        res += isprime[i];
    }
    return res;
}

int main() {
    init();
    int n;
    while (cin >> n) {
        cout << nprimes(n) << "\n";
    }
}

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

using namespace std;

int HowManyPrimeNumbers1(const int);
int HowManyPrimeNumbers2(const int);
int MySqrt(const int);

int main(){
	int n;

	while(cin >> n){
		printf("%d\n",HowManyPrimeNumbers2(n));
	}

	return 0;
}

int HowManyPrimeNumbers1(const int n){
	int i,j,buf,cnt = 1;

	for(i=3;i<=n;i+=2){
		buf = (int)sqrt((double)i);

		for(j=3;j<=buf;j+=2){
			if((i % j) == 0){
				cnt--;
				break;
			}
		}

		cnt++;
	}

	return cnt;
}

int HowManyPrimeNumbers2(const int n){
	int i,j,cnt,root,rt;

	// 3 から n までの奇数の個数 + 1 を n に代入
	cnt = ((int)((((double)(n - 2)) / 2) + 0.5)) + 1;

	// 最大処理数を求める
	root = (int)sqrt((double)n);

	// a
	for(i=3;i<=root;i+=2){
		rt = MySqrt(i);
		for(j=3;j<=rt;j+=2){
			if((i % j) == 0){
				cnt += (n / i);
				break;
			}
		}
		cnt -= (n / i);
	}

	return n;
}

int MySqrt(const int i){
	int n;

	n = i - 1;

	return (int)(1 + (1 / 2) * (double)(i - 1) - (1 / 8) * (double)(i - 1) * (i - 1) + (1 / 16) * (double)(i - 1) * (i - 1) * (i - 1));
}