Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

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<iostream>
#include<vector>

using namespace std;

int main()
{
	int i,j;
	char array[1000010];
	
	for(i=0;i<1000001;i++)
		array[i]='1';
	
	array[0]=array[1]='0';
	
	for(i=0;i<1000001;i++)
	{
		if(array[i]=='1')
		{
			for(j=2;i*j<1000001;j++)
				array[i*j]='0';
		}
	}
	
	vector<int> ans;
	
	for(i=0;i<1000001;i++)
	{
		ans.push_back(0);
	}
	for(i=1;i<1000001;i++)
	{
		ans[i]+=ans[i-1];
		ans[i]+=(int)array[i]-48;
	}
	
	int inp;
	
	cin >> inp;
	cout << ans[inp] << endl;
}

C++: #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10000000+5;
int prime[maxn];
bool p[maxn];
int cnt=0;
void is_prime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=maxn;i++)
        if(p[i]) {
            prime[cnt++]=i;
            for(int j=i*i;j<=maxn;j+=i)
                 p[j]=false;
        }
}
int main()
{
    is_prime();
    int n;
    while(scanf("%d",&n)==1)
    {
        int k=lower_bound(prime,prime+cnt,n)-prime;
        if(prime[k]==n) k++;
        printf("%d\n",k);
    }
    return 0;
}

C++: /*#include <cstdio>
#define MAX 1000

int main(){
	int n;
	bool c[MAX]={true};
	int t[MAX];t[0] = 0;
	for(int i = 2;i < MAX;i++){
		for(int j = i;i*j < MAX;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < MAX;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}*/

#include <cstdio>

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
bool IsPrime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i == 0){return false;}
    }
    return true;
}
 
int main(void) {
	int n;
 while(cin >> n){	
    int count = 1;
    
    for(int i=3;i<=n;i=i+2){
        if(IsPrime(i)) count++;
    }
    cout << count << endl;
    count = 0;
}

    return 0;
}

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

int count_prime( unsigned int const& n )
{
    if ( n <= 0 || 1000000 <= n ) return -1;
    std::vector<bool> memo_prime( n+1, true );
    for ( unsigned int i = 2; i < n; ++i )
    {
        for ( unsigned int j = 2; i*j <= n; ++j )
        {
            memo_prime.at(i*j) = false;
        }
    }
    memo_prime.at(0) = memo_prime.at(1) = false;
    memo_prime.at(2) = true;
    return std::count( memo_prime.begin(), memo_prime.end(), true );
}

int main()
{
    int n;
    while( std::cin >> n)
        std::cout << count_prime(n) << std::endl;
    return 0;
}

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

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

C++: #include <iostream>
#include <vector>
//#include <math.h>
//#include <string>
#include <cmath>
#include <iomanip>

int main();
int count_prime_number(int n);

int main(){
	int input;
	std::vector<int> answer;
	
	
	//for (int i = 0; i < 3; i++){
		//std::cin >> input;
	while (std::cin >> input){
		answer.push_back(count_prime_number(input));
	}

	for (int i = 0; i < answer.size(); i++){
		std::cout << answer[i] << std::endl;
	}

	//while (1);
	return 0;
}

/**
* nまでの素数の個数を出力する
* args:数値n
* return:素数の個数
* 参考:http://tsg.ne.jp/TT/tsg/c/mansaku/P01.html
*/
int count_prime_number(int n){
	int rtn = 0;

	//2だけ個別チェック
	if (n >= 2){
		rtn++;
	}

	for (int i = 3; i <= n; i += 2)
	{
		bool is_prime_num = true;
		for (int j = 3; j <= sqrt(i); j += 2)		//ルートi以上のiの約数はルートi以下のiの約数と対になっているので範囲はルートiまででいい
		{
			if (i % j == 0)
			{
				is_prime_num = false;
				break;
			}
		}

		if (is_prime_num){
			rtn++;

			//デバッグ
			//std::cout << i << std::endl;
		}
	}

	return rtn;
}

C++: //#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
#include <time.h>

using namespace std;

#define N_MAX 1000000

int kouho[N_MAX / 2];

int main(){

	clock_t c1,c2;
	c1 = clock();

	vector <int> sosuu;
	int check;
	//int kouho[N_MAX / 2];
	int n;
	int cnt;


	for (int i = 0; i < N_MAX / 2; i++){
		kouho[i] = i * 2 + 1;
	}
	kouho[0] = 0;

	sosuu.push_back(2);
	check = 3;

	while (check < 1000){
		sosuu.push_back(check);
		for (int i = check; i < N_MAX; i += (check*2)){
			kouho[(i - 1) / 2] = 0;
		}

		for (int i = check/2; i < N_MAX / 2; i++){
			if (kouho[i] != 0){
				check = kouho[i];
				break;
			}
		}
	}


	
	while (cin >> n){
		cnt = 0;
		if (n <= 1000){
			for (int i = 0; i < sosuu.size(); i++){
				if (sosuu[i] <= n)cnt++;
				else break;
			}
		}
		else{
			cnt += sosuu.size();
			for (int i = 0; i < N_MAX /2; i++){
				if (kouho[i] > n){
					break;
				}
				else{
					if (kouho[i] != 0)cnt++;
				}
			}
		}
		cout << cnt << endl;
	}

	c2 = clock();

	cout << "time = " << (double)(c2 - c1) / CLOCKS_PER_SEC << "[sec]" << endl;


	return 0;
}

C++: #include <iostream>
int main(){
    int i,j,ch[1000000];

    for(i=0;i<1000000;i+=2){ch[i]=0;ch[i+1]=1;}

    ch[1]=0;
    ch[2]=1;

    for(i=3;i<1000;i+=2) if(ch[i]) for(j=i<<1;j<1000000;j+=i) ch[j]=0;

    for(i=3;i<1000000;i++) ch[i]+=ch[i-1];

    while(cin>>i) cout<<ch[i]<<endl;

    return 0;
}

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

int main(void){
    int num;
    while(cin>>num){
        int ans=0;
        for(int i=2;i<=num;i++){
            int check=0;
            for(int j=2;j*j<=i;j+=2){
                if(i%j==0){check++;break;}
            }
            if(check==0)ans++;
        }
        cout<<ans<<endl;
    }
}

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

long long a[999999]={2,3,5};
int count=3;
long long maxc=6;
int main(){

	int t;
	while(cin>>t){

		if(t<maxc){
			int i=0;
			for(;a[i]<=t&&i<count;i++);
			cout<<i<<endl;
		}else{
			for(long long j=maxc;j<=t;j++){
				bool r=true;
				for(int i=0;i<count&&a[i]*a[i]<=j;i++){
					if(!(j%a[i]))
						r=false;
				}
				if(r)
					a[count++]=j;
			}
			maxc=t+1;
			cout<<count<<endl;
		}

	}

	return 0;
}