Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <iostream>

int main() {
	int n;
	while (std::cin >> n) {
		int c = 0;
		for (int i = 2; i <= n; i++) {
			bool fg = true;
			for (int j = 2; j < i; j++)
				if (!(i % j))
					fg = false;
			if (fg)
				c++;
		}
		std::cout << c << std::endl;
	}
}

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

int prime[MAX_N];
bool is_prime[MAX_N+1];

int sieve(int n) {
  int p = 0;
  for(int i=0;i<=n;i++) {
    is_prime[i] = true;
  }
  is_prime[0] = is_prime[1] = false;
  for(int i=2;i <= n;i++) {
    if(is_prime[i]) {
      prime[p++] = i;
      for(int j=2 * i;j<= n;j += i) is_prime[j] = false;
    }
  }
  return p;
}

int main() {
  int n;
  cin >> n;
  cout << sieve(n) << endl;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cmath>

using namespace std;

int pri[1000009];
int vis[1000009];

void fun()
{
    int num=0;
    for(int i=2;i<=999999;i++)
    {
        if(vis[i]==0)
        {
            pri[num++]=i;
            for(int j=i;j<=999999;j+=i)
                vis[j]=1;
        }
    }
}

int main()
{
    int n;
    fun();

    while(~scanf("%d",&n))
    {
        int num=0;
        for(int i=0;;i++)
        {
            if(pri[i]>n)break;
            else num++;
        }
        printf("%d\n",num);
    }
    return 0;
}

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

int const M=31;
int a,hantei[M];

int main(){
  hantei[0]=hantei[1]=1;
  for(int i=2;i<M;i++){
    if(hantei[i]==0){
      for(int j=2;j*i<M;j++){
	if(j*i<M){
	  hantei[j*i]=1;
	}
      }
    }
  }
  for(;cin>>a;){
    int count=0;
    for(int i=0;i<=a;i++){
      if(hantei[i]==0){
	count++;
      }
    }
    cout<<count<<endl;
  }
}

C++:  #include <iostream>
using namespace std;
int main(){
	int n , i , j , ans , num ;
	while(cin>>n){
		ans=0;
		for( i=2 ; i<=n ; i++ ){
			num=0;
			for( j=2 ; j<=n ; j++ ){
				if( i%j ==0 )
					num++;
			}
			if( num<2 )
				ans++;
		}
		cout << ans << endl;
	}
}

C++: #include <stdio.h>
 
using namespace std;
 
int calcLimit(int n){
    int limit;
    for(limit=0;limit*limit<=n;limit++);
    return limit-1;
}
 
int main(){
    int n,count,limit;
 
    while(scanf("%d",&n)!=EOF){
        count=0;
        int* array = new int[n+1];
        for(int i=1;i<=n;i++)array[i]=0;
        limit = calcLimit(n);
        for(int i=2;i<=limit;i++){
            if(array[i] == 0)
            {
                for(int j=2*i;j<=n;j+=i){
                    if(array[j]==0){
                        array[j]=1;
                        count++;
                    }
                }
            }
        }
        printf("%d\n",n-(count+1));
    }
 
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(x=0;x<to;x++)
#define rep2(x,from,to) for(x=from;x<to;x++)

using namespace std;



int erat(int num){
int i,cnt=1;
//	vector<int> Prime(num+2); // 素数リスト
	vector<char> Find(num+2); // 探索リスト
	for(int i = 2; i <= num; i++) Find[i] = '0';
	for(int i = 2; i*i < num; i++){
    	if(Find[i] > '0') continue; // すでに除いた数は飛ばす

    // j++からj+=iになったのでループ内でiの倍数のみが処理される。だいぶ高速化
    	for(int j = i * 2; j< num; j += i) {
        	if(Find[j]=='0') Find[j] = '1';
    	}
	}
// 2の倍数の素数は2だけなので奇数のみを判定
//	Prime.push_back(2);
//	for(int i = 3; i*i < num; i += 2){
//    	if(Find[i]='0') Prime.push_back(i);
//	}
	rep2(i,3,num) if(Find[i]=='0' && i % 2) { cnt++;}
	return cnt;
}

int main(void){

int num;

	while(cin >> num){
//		cnt = erst(num);
		cout << erat(num) <<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
#define thefor(i,end) for (i=0;i<end;i++)
bool isprime(int n)
{
	if(n==1)return false;
	if(n==2)return true;
	for (int i=3;i<n;i++)
	{
		if (n%i==0)return false;
	}
	if (i==n)
		return true;		
	else
		return false;
}
int main()
{
	bool prime[1000010];
	memset(prime,1,1000010);
	prime[0]=prime[1]=0;
	int i,j,n,sum;
	for (i=2;i<1000000;i++)
	{
		if (prime[i])
		{
			for (j=2;i*j<1000000;j++)
			{
				prime[i*j]=false;
			}
		}
	}
	while(cin>>n)
	{
		sum=0;
		for(i=2;i<=n;i++)
		{
			sum+=prime[i];
		}
		cout<<sum<<endl;

	}	
	return 0;
}

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

int main(){
  int n;

  while(cin >> n){
    int cnt = 0;
    
    for(int i = 1; i <= n; i++){

      if(i % 2 == 0|| i % 3 == 0 || i % 5 == 0) continue;

      int yakusuu = 0;

      for(int j = 1; j <= i; j++){
        if(i % j == 0) yakusuu++;
      }

      if(yakusuu == 2) cnt++;

    }
    
    cout << cnt + 3 - 1 << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int i;
  int count;
  vector<int> ans;
  bool flag;

  while(cin >> i){
    if(cin.eof()){
      break;
    }
    count = 0;
    for(int d = 2; d <= i; d++){
      flag = true;
      for(int dd = 2; dd < d; dd++){
	if(d%dd == 0){
	  flag = false;
	  break;
	}
      }
      if(flag){
	count++;
      }
    }
    ans.push_back(count);
  }
  for(int& d : ans){
    cout << d << endl;
  }

}

C++: #include<cstdio>
int n,ans;
bool p[1000005]={1,1};
int main()
{
	int i,j;
	for(i=2;i<=997;i++)
		if(!p[i])
			for(j=i;j*i<1000000;j++)
				p[j*i]=1;
	while(~scanf("%d",&n))
	{
		ans=0;
		for(i=2;i<=n;i++)
			if(!p[i]) ans++;
		printf("%d\n",ans);
	}
}

C++: #include<stdio.h>
#include<math.h>
int solve(int n,int start,int end);
int nextprime(int n);
int prime[500000];
int getprime(void);
int main(void)
{
	int n;
	int all = getprime();
	while (scanf("%d", &n) == 1)
	{
		
		printf("%d\n",solve(n,0,all)+1);
	}
}
int solve(int n,int start,int end)
{

	if (end == start)
	{
		if (n < prime[end])
			return end - 1;
		else return end;
	}
	int k = (end + start) / 2;
	if (n < prime[k])
		return solve(n, start, k-1);
	if (n > prime[k])
		return solve(n, k+1, end);
	return k;
}
int nextprime(int n)
{
	for (int i = n + 1;; i++)
	{
		int pan=1;
		for (int k = 2; k <= sqrt(i); k++)
		{
			if (i%k == 0)
			{
				pan = 0;
				break;
			}
		}
		if (pan)
			return i;
	}
}
int getprime(void)
{
	int i = 1, n = 0;
	while ((i = nextprime(i)) < 999999)
	{
		prime[n] = i;
		n++;
	}
	return n-1;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int count = 0;

bool isPrime(int n)
{
    if (n == 2) return true;
    else if (n%2 ==0 || n<0)
    {
        return false;
    }
    else
    {
        int k = sqrt(n);
        for (int i=3; i<=k; i+=2)
        {
            if (n%i == 0)
            {
                return false;
            }
        }
        return true;
    }
}

int main()
{
    int count = 0;
    int n;
    while (scanf("%d", &n) != EOF)
    {
        for (int i=2; i<=n; i++)
        {
            if (isPrime(i))
            {
                count ++;
            }
        }
        printf("%d\n",count);
        count = 0;
    }


    return 0;
}