Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int isPrime(int n){
    int i;
    if(n == 2)  return true;
    else if(n < 2 || n % 2 == 0)    return false;
    else{
        i = 3;
        while(i <= sqrt(n)){
            if(n % i == 0)  return false;
            i += 2;
        }
    }
    return true;
}
 
int main(void){
    int n, i, cnt;
    while(cin >> n){
        cnt = 1;
        for(i = 3; i <= n; i = i + 2){
            if(isPrime(i))  cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

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

int main(){
	const int max_num=1001000;
	int prime[max_num];
	int prime2[max_num];
	int min_prime[169]={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 };
	int sosuu=0;
	int k=169;

	for(int i=0;i<169;i++){
		prime[i]=min_prime[i];
	}
	for(int i=1011;i<max_num;i+=2){
		sosuu=0;
		for(int j=0;j<169;j++){
			if(i%min_prime[j]==0){
				sosuu++;
			}
		}
		if(sosuu==0){
			prime[k]=i;
			k++;
		}
	}
	int l=0;
	for(int i=0;i<max_num;i++){
		if(i>=prime[l]){
			l++;
		}
		prime2[i]=l;
	}

	int n;

	while(cin>>n){
		cout<<prime2[n]<<endl;
	}

	return 0;
}

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

const int M = 110000;

bool p[M];
int prime_n[M];

void prime() {
  fill(p, p+M, true);
  p[0] = p[1] = false;
  for(int i = 2; i*i < M; i++) {
    if(p[i]) {
      for(int j = 2; i*j < M; j++) {
        p[i*j] = false;
      }
    }
  }

  int count = 0;
  for(int i = 2; i < M; i++) {
    if(p[i]) prime_n[i] = ++count;
    else prime_n[i] = count;
  }
}

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

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

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		vector<int> prime;
		
		if (n >= 2){
			prime.push_back(2);
		}
		for (int i = 3; i <= n; i += 2){
			int j;
			for (j = 1; j < prime.size(); j++){
				if (i % prime[j] == 0){
					break;
				}
			}
			if (j == prime.size()){
				prime.push_back(i);
			}
		}
		printf("%d\n", prime.size());
	}
	
	return 0;
}

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

using namespace std;

int main(){
	int flag;
	long cnt;
	long N[30];
	for(int i=0;i<30;i++) cin >> N[i];
	for(int i=0;i<30;i++) {
		cnt = 0;
		for(int j=2;j<=N[i];j++) {
			flag = 1;
			for(int k=2;k<(sqrt(j))+1;k++) if(j!=k && 0==j%k) flag = 0;
			cnt += flag;
		}
		cout << cnt << endl;
	}
	return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

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

  int n;
  while(true){
	if(!(cin >> n)) return 0;
	cout << cnt[n] << endl;
  }
  
  return 0;
}

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

int judgeprime(long num){
  int primeflag=1,i;

  if(num%2==0)primeflag=0;
  for(i=3;i<sqrt(num);i+=2){

    if( num%i==0 ){
      primeflag=0;
      break;
    }

  }

  if(num==0||num==1||num==4){primeflag=0;}
  else if(num==2){primeflag=1;}

  return primeflag;

}

int main(void){
  long i,num;
  int much;

  while( scanf("%ld",&num) != -1 ){

    much=0;

    for(i=1;i<=num;i++){
      much+=judgeprime(i);
    }

    printf("%d\n",much);

  }

  return 0;  
}

C++: #include <stdio.h>

#define MAX (999999)

int main(void)
{
	int i, j;
	bool p[MAX + 1] = {true};
	// ツェツ素ツ青板表ツ催ャツ青ャツづ可使ツづつスツェ
	int n, ans;
	
	// ツつアツづつゥツづァツ素ツ青板表ツ催ャツ青ャ
	p[0] = p[1] = true;
	for (int i = 2; (i * i) <= MAX; i++){
		if (p[i]){
			for (int j = 2; i * j <= MAX; j++){
				p[i * j] = false;
			}
		}
	}
	// ツつアツつアツづ慊づ！
	
	// ツ本ツ氾板つ「ツづつュツづヲツー
	while (scanf("%d", &n) != EOF){
		ans = 0;
		for (i = 0; i < n; i++){
			if (p[i]){
				ans++;
//				printf("%d:", i);
			}
		}
		printf("%d\n", ans);
	}
	
	return (0);
}

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

int main(){
  bool is_prime[1000000];

  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<1000000i++){
    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;
}

C++: #include "stdio.h"
//#include"time.h"
const int MAX_V = 1000000; // 100????????§????´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°,0????´???°??§?????????
int main() {
    int i, k, n;
//    clock_t start, now;//??£?¨?
    for(i = 2; i <= MAX_V; i++){
        prime[i] = 1; // 2??\???????´???°??¨??????
    }
    for(i = 2; i * i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°???2?????\???????????°????´???°??§?????????
            }
        }
    }
    while (1) {
        int cnt = 0;
        scanf("%d",&n);
//        start = clock(); // ????§???????
        if (n == EOF)break;
        for(i = n;1 <= i;i--){
            if(prime[i] == 1){  //??????????´???°
                cnt++;
            }
        }
//        now = clock(); // ????????????
        printf("%d\n",cnt);//for?????????????????????
//        printf("%f\n", (double)(now - start) / CLOCKS_PER_SEC);
    }
    return 0;
}
//????¨??????¨????????????????????????