Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

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

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>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//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);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool p[1000000];

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


int main() {
  int n, count;

  prime();
  while(cin >> n) {
    count = 0;
    for(int i = 2; i <= n; i++) {
      if(p[i] == true)count++;
    }
    cout << count << endl;
  }
}

C++: #include<stdio.h>
int prime[1000000];
int main() {
	prime[0] = -1;
	prime[1] = -1;
	for (int i = 2; i<1000000; i++) {
		if (prime[i] == 0) {
			prime[i] = 1;
			for (int j = i * 2; j<1000000; j += i)prime[j] = -1;
		}
	}
	int now;
	while (~scanf("%d", &now)) {
		int ans = 0;
		for (int i = 1; i<now + 1; i++)if (prime[i] == 1)ans++;
		printf("%d\n", ans);
	}
}

C++: #include <iostream>
#include <list>
#include <algorithm>

int main(){
	int NUM;
	while(std::cin >> NUM){
		std::list<int> numList,primeList;
		if(NUM<2){
			return 0;
		}
		for(int i=2;i<=NUM;++i){
			numList.push_back(i);
		}
	
		for(int i=numList.front();i<std::sqrt(NUM);i=numList.front()){
			primeList.push_back(i);
			numList.erase(std::remove_if(numList.begin(),numList.end(),[&](int num){return num%i==0;}),numList.end());
		}
		std::copy(numList.begin(),numList.end(),std::back_inserter(primeList));

		std::cout << primeList.size() << std::endl;
		}
	return 0;
}

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

#define N 1000000

using namespace std;

int main()
{
  bool primes[N];

  fill(primes+2, primes+N, true);

  // eratos
  for(int i = 2; i < N; ++i)
    if(primes[i])
      for(int j = i+i; j < N; j += i)
	primes[j] = false;

  int n, count;
  while(cin>>n){
    count = 0;
    for(int i = 2; i <= n; ++i)
      if(primes[i]) ++count;

    cout << count << endl;
  }

  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    n++;
    int ans=0;
    int math[n];
    for(int i=0;i<n;i++){
      math[i]=0;
    }
    n--;
    math[1]=1;
    for(int i=2;i<n+1;i++){
      int bell=i;
      if(math[i]==0){
	ans++;
	math[i]=1;
      }
      while(bell<=n){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      } 
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>

using namespace std;

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

int main(){
	int n;
	while(cin >> n){
		bool bin[1000000] = {};
		int m = 0;
		FOR(i,2,n+1)if(!bin[i]){
			REP(j,n/i+1)bin[i*j] = true;
			m++;
		}
		cout << m << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main()
{
	vector<long long int>D(1000001 , 1);
	D[0] = 0;
	D[1] = 0;
	for(long long int i = 2; i <= sqrtl(1000001); i++)
	{
		if(D[i])
		{
			long long int j = 2;
			while(i*j < 1000001)
			{
				D[i*j] = 0;
				j++;
			}
		}
	}
	for(long long int i = 1; i < 1000001; i++)
	{
		D[i] += D[i - 1];
	}
	long long int n;
	while(cin >> n)cout << D[n] << endl;
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


void initialize(vector<int> &search_list, int num);

void era(vector<int> &search_list, vector<int> &prime_list, int num);
  

int main(int argc, char* argv[]){
  
  int num;

  while (cin >> num){
    if (num == 1){
      cout << 0 << endl;
    }
    else{
      vector<int> search_list, prime_list;
      initialize(search_list, num);
      era(search_list, prime_list, num);
      cout << prime_list.size() << endl;
    }
  }
  return 0;
}

void initialize(vector<int> &search_list, int num){
  for (int i=2; i<=num; ++i){
    search_list.push_back(i);
  }
  return;
}

void era(vector<int> &search_list, vector<int> &prime_list, int num){
  do{
    vector<int>::iterator it = search_list.begin();
    int count = 1;
    int N = *it;
    prime_list.push_back(*it);
    while ((N*count) <= num){
      it = find(search_list.begin(), search_list.end(), (N*count));
      if (it != search_list.end()){
	it = search_list.erase(it);
      }
      ++count;
    }
  } while (!search_list.empty());
}

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

#define MAX 1000000

static bool gosei[MAX];

void b() {
	for (int i = 2; i <= sqrt(MAX); i++)
		if (gosei[i] == false) {
			for (int j = 2, k = 0; (k = i*j) <= MAX; j++)
				gosei[k] = true;
		}
}

int c(int n) {
	int cnt = 0;
	for (int i = 2; i <= n; i++)
		if (!(gosei[i]))cnt++;
	return cnt;
}

int main() {
	b();
	int n;
	while (cin >> n)
		cout << c(n) << endl;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;

  vector<int> nums;
  nums.reserve(n+1);
  for (int i = 0; i <= n; i++)
    nums.push_back(i);

  for (int i = 2; i <= n; i++) {
    if (nums[i] == 0)
      continue;
    int hoge = nums[i];
    for (int j = i+1; j <= n; j++) {
      if (nums[j] == 0)
        continue;
      else if (nums[j] % hoge == 0)
        nums[j] = 0;
    }
  }

  int result = 0;
  for (int i = 2; i <= n; i++)
    if (nums[i])
      result++;
  cout << result << endl;
  return 0;
}