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<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 999999
bool prime[MAX-1];
int main(void){ 
  
  prime[0] = prime[1] = false;
  //memeset(prime,sizeof(prime),true);
  fill(prime,prime+MAX,true);
  int ans[1000000];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  for(int i = 2 ; MAX > i * i ; i ++){
    ans[i] = ans[i-1] + prime[i];
    if(prime[i]){
      for(int j = i + i ; MAX > j * j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  //  for(int i = 0 ; i < 10 ; i ++)cout<<ans[i]<<endl;
  int n;
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std; 

int list[1000000]={2, 3, 5, 7, 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, 127, 131, 137, 139, 149, 151, 157, 163,
 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757,
 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil,input,mid;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	lo=1087;
	a=180;
	while(lo<=100003)
	{
		if(Prima(lo))
		{
			list[a]=lo;
			a++;
		}
		lo+=2;
	}
	//printf("%d",list[78498]);
	while(scanf("%ld",&input)!= EOF)
	{	
	lo=0;
	hi=78497;
	/*while(lo<=hi)
        {
            mid=(lo+hi)/2;
            if (list[mid]<input)
            {
                lo=mid+1; 
            } 
            else if(list[mid]>input)
            {
                hi=mid-1; 
            }
            else 
            {
                break; 
            } 
        }*/
	while(input>=list[lo])
	{
		lo++;
	}
	printf("%d\n",lo);
	}
	return 0; 
}

C++: #include <iostream>
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 res=0;
for(int i=2;i<=n;i++){
if(is_prime(i)) res++;
}
printf("%d\n",res);
}
}

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

using namespace std;

int isprime(int x){
	int i;
	if(x == 2 || x == 3) return 1;
	else if(x % 2 == 0) return 0;
	else{
		for(i = 3; i <= sqrt(x); i += 2){
			if(x % i == 0) return 0;
		}
		return 1;
	}
}

int main(){
	int n, i, count;
	while(cin >> n){
		count = 0;
		for(i = 2; i <= n; i++){
			if(isprime(i) == 1) count++;
		}
		cout << count << endl;
	}
	return 0;
}

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

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

C++: #include <iostream>
int a[1000000];
bool tf[1000000];
void f(){
    for(int i = 0;i < 1000000;i++){
        tf[i] = true;
    }
    tf[0] = tf[1] = false;
    for(int i = 2;i < 1000000;i++){
        if(tf[i]){
            for(int j = 2 * i;j < 1000000;j += i){
                tf[j] = false;
            }
        }
    }
    int sum = 0;
    for(int i = 1;i < 1000000;i++){
        sum = (tf[i] == true)? sum + 1 : sum;
        a[i] = sum;
    }
}
int main(){
    f();
    int x;
    while(std::cin >> x){
        std::cout << a[x] << "\n";
    }
    return 0;
}

C++: //AOJ 0009 Prime Number
//2016.6.25
//Algorithm:Prime
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;

const int maxn=1000006;
bool prime[maxn];
int n;
int cnt[maxn];

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

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

const int C = (int)1e8;

bool isprime[C];
int prime[C];

void init() {
  fill(isprime, isprime+C, true);
  isprime[0] = isprime[1] = false;
  for (auto i=2; i<C; i++) {
    if (isprime[i]) {
      for (auto j=2; i*j<C; j++) {
	isprime[i*j] = false;
      }
    }
  }
  prime[0] = 0;
  for(auto i=1; i<C; i++) {
    prime[i] = ((isprime[i]) ? prime[i-1]+1 : prime[i-1]);
  }
}

int main() {
  init();
  int n;
  while (cin >> n) {
    cout << prime[n] << endl;
  } 
}

C++: #include <stdio.h>

const int MAX_V = 100000;
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>
using namespace std;
int main()
{
long n,i,j,*nn;
for(;;){
cin>>n;
if(cin.eof())break;
nn=new long [n+1];
nn[1]=0;nn[2]=1;
for(i=3;i<=n;i+=2)nn[i]=1;
for(i=4;i<=n;i+=2)nn[i]=0;
for(i=3;i*i<n;){
for(j=i;i*j<=n;j+=2)nn[i*j]=0;
i++;while(nn[i]=0)i++;
}
for(i=2,j=0;i<=n;i++)if(nn[i]==1)j++;
cout<<j<<endl;
delete [] nn;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map> // pair
#include <set>
#include <string>

#define MAXSIZE 200000
#define PI 3.141592653589
using namespace std;

template<typename T>
T add(T a,T b){
  return a+b;
}

namespace A
{
  int f(void){
    return 1;
  }
}

int main(){
  int n;
  while (std::cin >> n) {
    int count=0;//素数の数
    for(int i=2;i<=n;i++){
      int flag=0;
      for(int j=2;j<=sqrt(i);j++){
        if(i%j==0){
          flag=1;
          break;
        }
      }
      if(flag==0){
        count++;
      }
    }
    std::cout << count << '\n';
  }

}