Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include <string>
#include<fstream>
#include<ctime>
#include<queue>

using namespace std;
#define LL long long
#define mxn 100010
#define mxe 1000010
#define eps 1e-4
#define inf 0x7fffffff

#include<iostream>
#include<cstdio>
#define INF 999999999;
#include<iostream>
using namespace std;

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i<= MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 2; i <= n; i ++)

using namespace std;

int main(void){
	for(int n, count = 0; cin >> n; cout << count << endl, count = 0){
		vector<bool> numberList(n + 1);

		rep(i, n) numberList[i] = true;

		rep(i, n) for(int j = i; i * j <= n; j ++) numberList[i * j] = !(numberList[i * j]);
		
		rep(i, n) if(numberList[i]) count ++;
	}

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