Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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

int main()
{
  bool p[1000001];
  int n, ans;

  for(int i=0; i<=1000000; i++){
    p[i] = (i<=1)? false : true ;
  }

  for(int i=2; i<=sqrt(1000000)+1; i++){
    if(p[i]){
      for(int j=i*2; j<=1000000; j+=i){
        if(j%i == 0)
        p[j] = false;
      }
    }
  }

  while( cin >> n ){
    ans = 0;
    for(int i=0; i<=n; i++){
      if(p[i]){
        ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<stdio.h>
int main() {
	int n,i,k,ans;
	int MAX_V=1000000;
	int prime[MAX_V];
	int sum[MAX_V+1];
	for(i=2;i<=MAX_V;i++) {
		prime[i]=1;
	}
	for(i = 2; i*i <= MAX_V; i++) { 
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	while(scanf("%d", &n) != EOF) {
		for(i=0;i<=n;i++) {
			sum[i+1]=sum[i]+prime[i];
		}
		ans=sum[n+1];
		printf("%d\n",ans);
	}
	return 0; 
}

C++: #include <iostream>
#define REP(i,n) for(int (i) = 0; i <= n; ++i)
using namespace std;

bool is_prime(int n){
    for (int i = 2; i*i <= n; i++) if(n%i == 0)return false;
    return n>=2;
}

int main() {
    int n;
    while(cin>>n){
        int ret = 0;
        REP(i, n)if(is_prime(i))ret++;
        cout<<ret<<endl;
    }
    return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		int num = 0;
		for (int i = 1; i <= n; i++) {
			if (i <= 3) {
				if (i == 2 || i == 3) num++;
				continue;
			}
			else {
				if (i % 2 == 0 || i % 3 == 0) continue;
				if (i % 6 != 1 && i % 6 != 5) continue;
				bool check = true;
				for (int j = 5; j * j <= i; j += 6) {
					if (i % j == 0) check = false;
					if (i % (j + 2) == 0) check = false;
					if (check == false) break;
				}
				if (check == true) num++;
			}
		}
		cout << num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;

bool isPrime(int num);

int main()
{
	int count = 0;
	/*int m = 2, n = 0, num;

	cin >> num;

	int *data = new int[num + 1];
	int *result = new int[num + 1];

	data[0] = 0;
	data[1] = 0;

	do
	{
		for (i = 2 * m; i < num + 1; i += m)
		{

		}
	}
	while
	{

	}*/
	const int N = 1000;
	std::vector<bool> isPrime(N + 1, true);    // ?´???°????????°?????¨??¨ON???
	for (int i = 2; i < N; ++i) {
		if (isPrime[i])
		{   
			count++;

			for (int k = i + i; k <= N; k += i)
				isPrime[k] = false;      // ?´???°????????°????´???°????????°?????¨???OFF???
		}
	}
	return 0;






	
}

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n) != EOF) {
		res = 0;
		while (!Eratos[n]) {
			n--;
		}
		printf("%d\n",Eratos[n]);
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vi prime_count;
void sieve(int max){
    int count = 0;
    vector<bool> table(max + 1, true);
    table[0] = false;
    prime_count.push_back(0);
    table[1] = false;
    prime_count.push_back(0);
    for(int i = 2; i <= max; i++){
        if(table[i]){
            count++;
            for(int j = 2; i * j <= max; j++){
                table[i * j] = false;
            }
        }
        prime_count.push_back(count);
    }
}

int main(){
    int n;
    sieve(1000000);
    while(cin>>n){
        cout << prime_count[n] << endl;
    }
    return 0;
}

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

using namespace std;

const int MAX_N = 1000000;

int N;

int len;
bool isPrime[MAX_N];
int num[MAX_N];				//the number of prime less than i

void sieve(){
	//init
	fill(isPrime, isPrime + MAX_N, true);
	isPrime[0] = isPrime[1] = false;
	num[0] = num[1] = 0;
	for(int i = 2; i < MAX_N; i ++){
		if(isPrime[i]){
			num[i] = num[i - 1] + 1;
			for(int j = 2 * i; j < MAX_N; j += i)
				isPrime[j] = false;
		}
		else{
			num[i] = num[i - 1];
		}
	}
}

int main(int argc, char const *argv[]){

	sieve();
	while(scanf("%d", &N) != EOF){
		printf("%d\n", num[N]);
	}

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;
while(~scanf("%d",&n)){
int* table =  new int[n+1];
fill((int*)table,(int*)table+n+1,1);
table[0]=0;
table[1]=0;

for(int i=2;i*i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j+=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+n+1,1));
}
}

C++: #include <stdio.h>

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    int i, k, v;
    for(i=2; i<MAX_V; i++){
        prime[i] = 1;
    }
    for(i=2; i*i<=MAX_V; i++){
        if(prime[i]){
            for(k=2*i; k<=MAX_V; k+=i){
                prime[k]=0;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

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

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

#define N_MAX 1000000

using namespace std;

int main(void)
{
	int n = 0;
	bool isNotPrime[N_MAX] = { false };
	
	isNotPrime[0] = true;
	int rootN = sqrt(N_MAX);
	for(int i = 2; i <= rootN; i++){
		for(int j = 2 * i; j < N_MAX; j += i){
			isNotPrime[j - 1] = true;
		}
	}
	
	while(cin >> n){
		//素数の数をカウント
		int cnt = 0;
		for(int i = 0; i < n; i++){
			if(!isNotPrime[i]){
				cnt++;
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}

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

int main(){
	int n;
	int a=0;
	while(cin >> n){
		for(int i = 0; i < n; ++i){
			for(int j = 2; j <= i; ++j){

				if(i%j == 0){
				if(i==j){
					++a;
				}else{
					break;
				}
				}
		}
	
	}
		cout << a << '\n';
}
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<int> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=false;
      v[1]=false;
    for(int i = 2;i<MAX;i++){
      if(v[i]==true){
        for(long long int  = (long long int)i*i;j<MAX;j=j*j){
         v[j]=false;
       }
      }
    }
    for(int i = 2;i<MAX;i++)v[i]+=v[i-1];
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      cout << v[a]<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main(){
    int X,ans,count;
    bool num[1000001]={};
    for(int i=2;i<=1000000;i++){
        if(!num[i]) 
        for(int j=i*2;j<=1000000;j+=i)  num[i] = true;
    }
    while(cin >> X)
    {
        count = 0;
        for(int i=2;i<=X;i++){
            if(!num[i]) count++;
        }
        cout << count << endl;
    }
    return 0;
}