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 <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--;
			if (n == 0)
				break;
		}
		if (n)
			printf("%d\n", Eratos[n]);
		else
			printf("0\n");
	}
	return 0;
}

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

using namespace std;

const int a[] = {1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209};

int func(int v)
{
	int b = v / 210;
	int c = -1;

	int left=0, right=48;
	do{
		int mid = (left+right)/2;
		if(a[mid] == v-b*210){
			c = mid;
			break;
		}else if(a[mid] < v-b*210)
			left = mid + 1;
		else
			right = mid - 1;
	}while(left<=right);

	return c == -1 ? -1 : b*48 + c;
}

int main(void)
{
	unsigned char* eratos = new unsigned char[28572000];
	fill(eratos, eratos+28572000, 0);
	eratos[0] = 1;

	int cnt = 4;
	int i, j, k, n;
	scanf("%d", &n);
	if(n==1) return 0;
	if(n==2) return 1;
	if(n<=4) return 2;
	if(n<=6) return 3;

	for(i=0; i*210<n; ++i){
		for(j=0; j<48; ++j){
			int v = i*210 + a[j];
			int pos;
			if(v>n)
				break;
			pos = func(v);
			if(!((eratos[pos/8]>>(pos%8))&1)){
				++cnt;
				for(k=v*2; k<=n; k+=v){
					int p = func(k);
					if(p != -1)
						eratos[p/8] |= 1<<(p%8); 
				}
			}
		}
	}

	printf("%d\n", cnt);
	delete[] eratos;

	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define SIZE_VALUE 1000005

int main(){
    bool prime[SIZE_VALUE];
    int i,count=0,input;
    memset(prime,0,sizeof(prime));
    for(i=2;i*i<SIZE_VALUE;i++){
        if(prime[i]==0)
        for(int j=i*i;j<SIZE_VALUE;j+=i){
            prime[j]=1;
        }
    }
    while(scanf("%d",&input)==1){
        count=0;
    for(i=2;i<=input;i++){
        if(prime[i]==0)
            count++;
    }
    printf("%d\n",count);
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string.h>
using namespace std;
vector<int> prime;
int sieve(int n){
   bool arr[n+1];
   int cnt=0;
   memset(arr,true,sizeof(arr));
   for(int i=2;i<=n;++i){
    if(arr[i]){
        prime.push_back(i);
        cnt++;
    }
    for(int j=0;j<prime.size()&&i*prime[j]<n;j++){
        arr[i*prime[j]]=false;
        if(i%prime[j]==0)break;
    }
   }
   return cnt;
}

int main(){
int num;
int a;
while(true){
    scanf("%d",&num);
    if(!num) break;
    a=sieve(num);
    printf("%d\n",a);
}
return 0;
}

C++: #include <stdio.h>
#include <iostream>

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(1){
    while(cin >> num){
        int count=0;
        // scanf("%d", &num);
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

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

#define MAX 1000000

using namespace std;

bool prime[MAX+1];
int T[MAX];

void eratos(int n) {
  for(int i = 0; i < n; i++) prime[i] = false;
  for(int i = 3; i <=n; i+=2)prime[i] = true;
  prime[2] = true;
  for(int i = 3, limit = (int)sqrt(n); i <= limit; i += 2) {
    if(!prime[i]) continue;
    for(int j = i*i, k = i*2; j <= n; j += k) prime[j] = false;
  }
}

void init() {
  eratos(MAX);

  for(int i = 0; i < MAX; i++) {
    T[i] = T[i-1];
    if(prime[i]) T[i]++;
  }
}

int main(void) {
  init();
  int n;
  
  while(cin >> n) cout << T[n] << endl;
  return 0;
}

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

int main() {
	bool prime[1000000]={false};
	prime[1]=true;
	prime[2]=false;
	int n;
	while(cin>>n){
		int cnt=0;
		
		for(int j = 2; j * j <= n ; j++)
            if(!prime[j])
                for (int k = 2; k*j <= n;k++)
                   prime[j*k] = true;
	
		for(int i=2;i<=n;i++)
			if(!prime[i]) cnt++;
		cout<<cnt<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0;
	while(cin >> N){
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N_MAX 100000

using namespace std;

int main(){
	
	int array[N_MAX],i,j,n, num = 0;
	
	while(cin>>n){
		num = 0;
		for (i=0;i<n;i++)
			array[i]=i+2;
		for (i=0;i<n;i++){
			for (j = (i+2); (i+2) * j <= n; j++)
				array[(i+2) * j - 2] = -1;}

	for (i = 0; i < n-1; i++){
    if (array[i] != -1)
	num++;
	}
	cout<<num<<endl;
	}
	cin>>n;
  
	return (0);
}

C++: #include<iostream>

int n;
bool *isPrime;

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

int main(){
	while(std::cin >> n){
		isPrime = new bool[n+1];
		std::cout << solve() << std::endl;
		delete[] isPrime;
	}
	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX (1000000)

int main(void)
{
	char prime[MAX + 1];
	int n;
	char buf[256];
	
	memset(prime, 1, sizeof(prime));
	
	prime[0] = prime[1] = 0;
	for (int i = 2; i * i < MAX; i++){
		if (prime[i] == 1){
			for (int j = i * 2; j <= MAX; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (fgets(buf, 256, stdin) != NULL){
		int ans;
		
		n = atoi(buf);
		
		ans = 0;
		for (int i = 2; i <= n; i++){
			ans += prime[i];
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

bool sieve[1000000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(std::cin.eof())break;
		for(int i=0;i<=n;i++)
		{
			ans+=sieve[i]?1:0;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	for(int i=0;i<1000000;i++){sieve[i]=true;}
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<1000000;i++)
	{
		for(int j=i*2;j<1000000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

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

	return 0;
}