Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    while (cin >> n)
    {
        int count = 0, p[n + 1] = {};
        for (int i = 2; i <= (int)sqrt(n); i++)
        {
            if (p[i] == 0)
            {
                for (int j = 2; i * j <= n; j++)
                {
                    p[i * j] = 1;
                }
            }
        }
        for (int i = 2; i <= n; i++)
        {
            if (p[i] == 0)
            {
                count++;
            }
        }
        OP(count)
    }

    return 0;
}

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;
}