Go: package main

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

func search(min, max int, channel chan int) {
	flag := false
	count := 0
	for i := min; i <= max; i++ { //1を除く入力値以下の数字
		for j := 2; j < i; j++ {
			if i%j == 0 {
				flag = true
				break
			}
		}
		if !flag {
			count++
		} else {
			flag = false
		}
	}
	channel <- count
	return
}

func main() {
	count := 0
	channel := make(chan int)
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		num, _ := strconv.Atoi(scanner.Text())
		for i := 2; i < num; i += 10 {
			if i+10 < num {
				count++
				go search(i, i+10, channel)
			} else {
				count++
				go search(i, num, channel)
			}
		}
		var ans int
		for i := 0; i < count; i++ {
			ans += <-channel
		}

		fmt.Println(ans)
	}
}

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

#define MAX_SIZE (1000000)

int prime[MAX_SIZE];

int main()
{
	int n;

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

	for (int i = 2; i < MAX_SIZE; i++){
		prime[i] = 1;
	}

	for (int i = 0; i < MAX_SIZE; i++){
		for (int j = i * i; j < MAX_SIZE; j += i){
			prime[j] = 0;
		}
	}

	for (int i = 1; i < MAX_SIZE; i++){
		prime[i - 1] += prime[i];
	}

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

	return (0);
}

C++: #include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int n;
	int count = 0;

	while (cin >> n) {
		count = 0;
		if (n >= 2) {
			count++;
		}
		FOR(i, 3, n) {
			FOR(t, 2, i - 1) {
				if (i%t == 0) {
					break;
				}
				if (t == i - 1) {
					count++;
				}
			}
		}
		cout << count << endl;
		
	}
	
	return 0;
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int max[30], sol[30], listID=0;
	
    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        min = 1;
        minID = 0;
        for (int i=0; i<listID; i++){
            if (max[i] < n && min <max[i]){
                min = max[i];
				cnt = sol[i];
            }
        }
        for (int i=min+1; i<=n; i++){
            if (IsPrime(i)) cnt++;
        }
        max[listID] = n;
        sol[listID] = cnt;
        listID++;
        printf("%d\n", cnt);
    }
    return 0;
}

int IsPrime(int n){
    int i;
    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

C++: #include <cmath>
#include <cstdio>
#include <map>
 
inline bool fermat_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        return (static_cast<int>(std::pow(2, n - 1)) % n) == 1;
    }
}
 
inline bool prime_test(int n) {
    if (n < 2) {
        return false;
    } else if (n == 2) {
        return true;
    } else {
        for (int i = 3; i < static_cast<int>(std::sqrt(n)); i += 2) {
            if ((n %= i) == 0) {
                return false;
            }
        }
    }
    return true;
}

int m[999999];

int main() {
    m[3] = 2;
    int n;
    while (~scanf("%d", &n)) {
        if (n == 2) {
            printf("1\n");
            continue;
        }
        for (int i = 5; i <= n; i += 2) {
            if (m[i] > 0)
                continue;
 
            m[i] = m[i - 2] + (fermat_test(i) && prime_test(i));
        }
        printf("%d\n", m[n % 2 == 0 ? n - 1 : n]);
    }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#pragma warning(disable:4996)

int main()
{
	
	int num, cnt;
	unsigned int i, j, k, data_num;
	int data[30];
	unsigned int sq_num;
	unsigned int *prime;

	for (data_num = 0; data_num <30; data_num++)
	{
		data[data_num] = -1;
		scanf("%d", &data[data_num]);
		if (data[data_num] < 0)
			break;
	}

	for (k = 0; k < data_num; k++)
	{

		sq_num = (int)sqrt((double)data[k]);
		prime = (unsigned int*)malloc(sizeof(unsigned int) * data[k]);
		prime[0] = 0;

		for (i = 1; i < data[k]; i++)
		{
			prime[1] = 1;
		}

		for (i = 1; i < sq_num; i++)
		{

			if (prime[i] == i)
			{
				for (j = (i + 1); (i + 1)* j <= data[k]; j++)
				{
					prime[(i + 1) * j - 1] = 0;
				}
			}
		}

		cnt = 0; 
		for (i = 0; i < data[k]; i++)
		{
			if (prime[i] == 1)
			{
				cnt++;
			}
		}
		printf("%d\n", cnt);
		free(prime);
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int N;

int main() {
    vector<bool> is_prime(1000000,true);
    vector<int> prime(1000000,0);
    is_prime[0] = is_prime[1] = false;
    prime[0] = prime[1] = 0;
    int p = 0;
    for(int i = 2; i <= 1000000; ++i){
        if(is_prime[i]){
            ++p;
            for(int j = i*2; j <= 1000000; j += i) is_prime[j] = false;
        }
        prime[i] = p;
    }

    for(int i = 0; i <= 30; ++i){
        cin >> N;
        cout << prime[N] << '\n';
    }
    return 0;
}

C++: #include <iostream>
#include <complex>
int main(){
	while(1){
		int ans=0;
		int n;
		if(scanf("%d",&n)==EOF)break;
		if(n==1){
			std::cout<<0<<std::endl;
		}else{
			if(n>=2)ans++;
			if(n>=3)ans++;
			if(n>=5)ans++;
			if(n>=7)ans++;
			if(n>=11){
				for(int i=11;i<=n;i+=2){
					bool prime=true;
					int iSqrt=sqrt(i);
					for(int k=3;k<=iSqrt;k+=2){
						if(i%k==0){
							prime=false;
							break;
						}
					}
					if(prime)ans++;
				}
			}
		std::cout<<ans<<std::endl;
		}
	}
}

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

int main(){
	int n,w=0;
	cin >> n;
	for(int j=n;j>1;j--){
		for(int i=2;i<j;++i){
			if(j%i == 0){
				break;
			}
			if(i=j-1){
				w++;
			}
		}
	}
	cout << w;	
	return 0;
}

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

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

int main(){
	int Cheat[1000000],cnt = 0;
	Cheat[0]=0;Cheat[1]=0;
	for(int i = 0; i < 1000000; i++){
		if(isPrime(i)){
			cnt++;
		}
		Cheat[i] = cnt;
	}
	while(true){
		int n;
		cin >> n;
		if(cin.eof()){
			break;
		}
		cout << Cheat[n] << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int NUM = 1000000;
  bool prime[NUM];
  prime[0] = false;prime[1] = false;
  for(int i=2;i<NUM;i++)prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;
  int n,c,i;
while(cin>>n){
for(c=0,i=0;i<=n;i++)if(prime[i])c++;
cout<<c<<endl;}}

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

const int N = 100000;

int main(void)
{
    bool a[N+1];
    int prime[N], n;
    rep(i,N+1)
    {
        a[i] = true;
    }
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
        cout << prime[n] << endl;
    
    return 0;
}

C++: #include <stdio.h>
int main(){
	int i,j,n,num;
	bool prime[1000000];
	bool flag=true;
	for(i=0;i<999999;i++) prime[i]=true;
	while(scanf("%d",&n)!=EOF){
		num=0;
		for(i=2;i<n+1;i++){
				for(j=i*2;j<n+1;j=j+i) prime[j]=false;
		}
		for(i=2;i<n+1;i++){
			if(prime[i]==true) num++;
		}
		printf("%d\n",num);
	}
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << n - primes.count() - 1 << " ";
  }
}