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<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=2000000;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

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

int main()
{
	int a,i=0,m=1e6;bool p[m]={0};
	for(i=2;i<m;i++)
	{
		for(a=i+i;a<m;a+=i)p[a]=1;
	}
	
	for(;cin>>a;)
	{
		i=0;
		for(m=2;m<=a;i+=!p[m++]);
		cout<<i<<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[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 <iostream>
#include <cmath>

bool eratosthenes(int n);

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    while (std::cin >> n) {
        int cnt = 0;
        for (int i = 2; i <= n; ++i)
            if (eratosthenes(i))
                ++cnt;
        std::cout << cnt << std::endl;
    }
}

bool eratosthenes(int n)
{
    if (n == 2) return true;
    if (n < 2 || n % 2 == 0) return false;
    int i = 3;
    double root_n = std::sqrt((double) n);
    while (i <= root_n) {
        if (n % i == 0) return false;
        i += 2;
    }
    return true;
}

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

using namespace std;
int N = 999999;
int prime[999999];
int status[999999/32];

bool Check(int N, int pos)
{
	return (bool)(N&(1<<pos));
}
int Set(int N, int pos)
{
	return N = N | (1<<pos);
}
void sieve()
{
	int i, j, sqrtN;
	sqrtN = sqrt(N);

	for(i=3; i<=sqrtN; i+=2)
	{
		if(Check(status[i/32], i%32) == 0)
		{
			for(j=i*i; j<=N; j+=(2*i))
				status[j/32] = Set(status[j/32], j%32);
		}
	}
	int k = 1;
	prime[0] = 2;
	for(int i=3; i<=N; i+=2)
	{
		if(Check(status[i/32], i%32) == 0)
			prime[k++] = i;
	}
}
int main()
{
	sieve();
	int k, num, count = 0;
	k=0;
    while(scanf("%d", &num)!=EOF)
    {
        k=0;
    	count = 0;

        for(int i=1; i<=num; i++)
        {
            if(i == prime[k])
                {
                    count++;
                    k++;
                }
        }
        printf("%d\n", count);
    }
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
   vector<int> primes(999999+1,1);
   primes[0]=primes[1]=0;
   for(int c=2;c<primes.size();c++)
   {
       if(primes[c] == 0) continue;
       for(int c2=c+c;c2<primes.size();c2+=c) primes[c2]=0;
   }
   for(int c=1;c<primes.size();c++) primes[c]+=primes[c-1];

   int query;
   while(cin>>query) cout<<primes[query]<<endl;
}

C++: #include<iostream>
#define MAX 1000000
using namespace std;
int main(){
	int n, cnt;
	bool prime[MAX];	
	
	while(cin >> n){
		prime[n] ={false};
		prime[1] = true;
		
		// ??¨??????????????????????????????
		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>
#include <cmath>

#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)

using namespace std;

#define MAX 1000000

bool flg[MAX]={0};

void init(){
    flg[1] = true;
    reep(i,2,MAX){
        bool f=true;
        reep(k,2,sqrt(i)){
            if(i%k==0){
                f=false;
                break;
            }
        }
        if(f){
            for(int k=i+i;k<MAX;k+=i){
                flg[k]=true;
            }
        }
    }
}

int main(){
    init();
    int n;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        reep(i,1,n+1){
            if(!flg[i]){
                ans++;
            }
        }
        printf("%d\n",ans);
    }
}

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

int main(){
	int num;
	int count = 0;
	int i,j;

	cout << "数字を入力してください" << endl << "number :";
	cin >> num;

	for(i=2; i<num; i++){
		for(j=2; j<i; j++){
			if(i%j ==0){
				break;
			}
		}
		if(j == i){
			count++;
		}
	}
	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 Prime[1000000];

int main() {
	for(int i=0;i<1000000;++i)Prime[i]=1;
	
	Prime[0]=0;
	Prime[1]=0;
	
	for(int i=2;i<1000000;++i){
		if(Prime[i]){
			for(int j=i*2;j<1000000;j+=i){
				Prime[j]=0;
			}
		}
	}
	
	int n,cnt;
	while(cin>>n){
		cnt = 0;
		for(int i=0;i<=n;++i){
			cnt+=Prime[i];
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int box[1000005];
int main()
{
	for(int i=0;i<=999999;i++)
		box[i]=1;
	box[1]=box[0]=0;
	int n;
    int rooted=sqrt(999999);
    for(int i=2;i<=rooted;i++)
        if(box[i])
            for(int j=2;j*i<=999999;j++)
                box[j*i]=0;
	while (cin >> n)
	{
		int s=0;
		for (int i=1;i<=n;i++)
			s+=box[i];
		cout << s << endl;
	}
}

C++: #include <stdio.h>

int main(void){
int n;
while(scanf("%d",&n)!=EOF){
int count=0;
for(int m=1;m<=n;m++){
bool check=true;
for(int i=2;i<m;i++){
if(i!=m && m%i==0){
chack=false;
}
}
if(check==true){
count++;
}
}
}
return 0;
}

C++: #include<iostream>
#include<string>
#include<new>
int main(){for(int m,n,o,c,d,e,i;!(std::cin>>n).eof();){if(n<3)e=n>1;else{bool*v=new bool[c=(n&1?n:--n)/2+1];memset(v,1,c);for(i=m=e=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;e++;for(d=o=m*2+1;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(i=1;i<c;)e+=v[i++];delete[]v;}printf("%d\n",e);}}