Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	a, _ := strconv.Atoi(scanner.Text())
	return a
}

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

func main() {
	for scanner.Scan() {
		n := nextInt()
		cnt := 0
		for i := 2; i <= n; i++ {
			if isPrime(i) {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

C++: #include <stdio.h>
  int main(){
   int i,j,n,hantei=0;
   int sum=0;
    while(scanf("%d",&n) != EOF){
    for(i=2;i<=n;i++){
      for(j=2;j*j<=i;j++){
        if(i%j != 0 || i == j){
            hantei += 0;
               }else{
                  hantei += 1;
                    }
}
if(hantei == 0){
sum++;
}
hantei=0;
}
printf("%d\n",sum);
sum=0;
hantei = 0;
}
return 0;
}

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


using namespace std;
#define MAX_NUM 999999


//int do_count(bool *isPrime, int n);

int main(){
  int n;
  bool flag = false;
  int numPrime[MAX_NUM];
  int pivot = 1;
  
  //  for(int i=0;i<MAX_NUM;i++){
  //numPrime[i] = 0;
  //  }
  
  while(cin >> n){
    int cnt=0;
    if(n < pivot){
      //      cout << "n < pivot" << endl;
      cnt = numPrime[n];
      cout << cnt << endl;
      continue;
      
    }
    
    //    if(n >= pivot){
    //  }
    
    for(int i=pivot+1;i<=n;i++){
      flag = false;
      //?´???°?????????????????§??????
      for(int j=2;j<=sqrt(i);j++){
	if(i%j==0){
	  flag = true;
	  break;
	}
      }
      if(flag){
	numPrime[i] = numPrime[i-1];
	continue;
      }else{
	numPrime[i] = numPrime[i-1] + 1;
      }
    }
    cnt = numPrime[n];
    cout << cnt << endl;
  }
}

C++: #include <stdio.h>

int main(){
	int sosuu[100000] = { 2, 3, 5 }, i, x, y = 3,n,z;
	
	while (scanf("%d", &n)!=0){
		z = 0; 
		for (i = 3; i < n + 1; i += 2){
			for (x = 0; x < y; x++){
				if (i % sosuu[x] == 0){ break; }
				if (x + 1 == y){ sosuu[y] = i, y++;}
			}
		}
		for (i = 0; i < y; i++){ if (sosuu[i] > n)break; z++; }
		printf("%d\n", z);
	}
	return 0;
}

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

int main(){
  int a;
  int i, j, k;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin>>a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt((double)a);
      for(i=2; i<=a_sqrt; i++){
        for(j=i; j<=a/i; j++){
          chk[j*i]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
bool p[M];
short cnt[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  cnt[0] = cnt[1] = 0;
  loop(i,2,M){
    cnt[i] = cnt[i-1] + p[i];
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n)cout<<cnt[n]<<endl;
}

C++: #include<cstdio>
#include<cmath>
#include<cstring>
int prime(long long num)
{
    for(int i=2;i<=sqrt(num);i++)
	if(num%i==0)
	    return 0;
    return 1;
}
int main()
{
    long long n;
    while (scanf("%lld",&n)!=EOF)
    {
    	int sum=0;
    	for (int i=2;i<=n;i++)
    	  if (prime(i)) sum++;
    	printf("%lld\n",sum);
	}
    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <ctime>
 
using namespace std;
 
int main()
{
    int n;
    vector<int> prime;
     
    //unsigned long t = time(NULL);
    prime.push_back(2);
	prime.push_back(3);
    while (scanf("%d", &n) != EOF){
		if (prime[prime.size() - 1] <= n){
			for (int i = prime[prime.size() - 1] + 2; i <= n; i += 2){
				bool p = true;
				for (int j = 0; prime[j] <= i / 2; j++){
					if (i % prime[j] == 0){
						p = false;
						break;
					}
				}
				if (p){
					prime.push_back(i);
				}
			}
		}
		
		int count;
		for (count = 0; count < prime.size() && prime[count] <= n; count++){
			;
		}
		printf("%d\n", count);
    }
     
    return 0;
}

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 <3; 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[i] = 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 <cmath>
using namespace std;

int main() {
	int n;

	while (cin >> n) {
		int count = 0;
		bool table[n + 1] = { false };
		int upper = sqrt(n);

		table[1] = true;

		for (int i = 1; i <= upper; i++) {
			if (table[i] == false) {
				table[i] = true;
				count++;
				for (int j = i; j <= n; j++) {
					if (j % i == 0) {
						table[j] = true;
					}
				}
			}
		}

		for (int i = 1; i <= n; i++) {
			if (table[i] == false) {
				count++;
			}
		}

		cout << count << '\n';
	}

	return 0;
}

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

using namespace std;

#define MAX_N 99999
#define MAX_D 30

bool prime_check(int n, int k = 2)
{
	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	int n;

	bool isprime[MAX_N + 1];

	for (int i = 2; i < MAX_N + 1; i++)
	{
		isprime[i] = prime_check(i);
	}

	while (cin >> n)
	{
		cout << count(isprime + 2, isprime + n + 1, true) << endl;
	}

	return 0;
}

C++: // BCC
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#include <queue>

// GCC
// #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define each(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define pb push_back
#define mp make_pair

typedef long long ll;

const int INF = 1 << 28;
const ll INFLL = 1ll << 56;


/**
 * ??¨????????????????????????
 * ?´???°??¨??¨?´???°?????????????????????
 */

const int SIEVE_SIZE = 1000000;

bool is_prime[SIEVE_SIZE];
vector<int> primes;

void eratosthenes()
{
	primes.clear();
	for (int i = 2; i < SIEVE_SIZE; i++) is_prime[i] = true;
	
	for (int i = 2; i * i < SIEVE_SIZE; i++){
		if (!is_prime[i]) continue;
		for (int j = i * i; j < SIEVE_SIZE; j += i){
			is_prime[j] = false;
		}
	}
	
	for (int i = 2; i < SIEVE_SIZE; i++){
		if (is_prime[i]) primes.pb(i);
	}
}

int sum[1000000];

int main()
{
	eratosthenes();
	each(p, primes) sum[*p]++;
	rep(i, 999999) sum[i + 1] += sum[i];
	
	int n;
	while (~scanf("%d", &n)){
		printf("%d\n", sum[n]);
	}
}

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=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;
}