Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 0
                        }
                }
        }
}

C++: #include <cstdio>
#define max_n 999999
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",n);
        int ans = 0;
        for(int i =0; i<max_n; i++){
            ans = 0;
            if(prime[i]>n){
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

using namespace std;

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

int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			bool check = isPrime(i);
			if (check) ans++;
		}
		cout << ans << endl;
	}
}

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

int Eratosthenes(int N){

  int count=0;
  bool* IsPrime = new bool[N];
  IsPrime[0] = false;
  IsPrime[1] = false;
  for(int i=2; i<=N;i++){
    IsPrime[i] = true;
  }
  for(int i=2; i*i<=N;i++){
    if(IsPrime[i]){
      for(int j=2*i; j<=N; j+=i)
        IsPrime[j] = false;
      }
  }
  for(int i=0; i<=N;i++)
    if(IsPrime[i]) count++;

  delete[] IsPrime;
  return count;
}

int main(void)
{
    int N[30]={};
    int count=0;
    int i=0;
    while(1){
      if(scanf("%d",&N[i])!=1)
        break;
      i++;
    }
    i=0;
    while(N[i]>0){
      count=Eratosthenes(N[i]);
      printf("%d\n",count);
      i++;
    }

    return 0;
}

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

bool Prime(int n);

int main(){

  int n;
  int sum;

  while(scanf("%d",&n)!=EOF){
    sum = 0;
    for(int i=3; i<=n; i+=2){
      sum += Prime(i);
    } 
    cout << sum+1 << endl;
  }

  return 0;
}


bool Prime(int n){

  if(n%2==0)
    return false;

  else{
    for(int i=3; i<=sqrt(n); i+=2){
      if(n%i == 0)
	return false;
    }
  }

  return true;
}

C++: #include<stdio.h>
#include<math.h>
int gurobal[1000001]={0};
int main(void)
{
	int n=0;
	int i=0,j=0;
	int heihoukon=0;
	int count=0;
	while(scanf("%d",&n)!=EOF)
	{
		count=0;
		gurobal[1]=0;
		for (i=2;i<=n;i++)
		{
			gurobal[i]=1;
		}
		(int)heihoukon=sqrt((double)n);
		for (i=2;i<=heihoukon;i++)
		{
			if (gurobal[i]!=0)
			{
				for (j=i*2;j<=n;j+=i)
				{
					gurobal[j]=0;
				}
			}
		}
		for (i=2;i<=n;i++)
		{
			if (gurobal[i]!=0)
			{
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000000] = {false};
  for(int i=2; i<1000; i++){
    if(!num[i]){
      for(int j = i*i; j<1000000; j+=i){
    num[j] = true;
      }
    }
  }
  int n;
  while(cin >>n){
    int ans = 0;
    for(int i=2; i<=n; i++){
      if(!num[i]){ans++;}
    }
    cout <<ans<<endl;
  }
  return 0;
}

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

#define MAX_NUM (1000000)

static int getPrimeNum(int maxVal);

int main(void)
{
  int n;
  
  while (std::cin >> n) {
    std::cout << getPrimeNum(n) << std::endl;
  }
  
  return 0;
}

static int getPrimeNum(int maxVal)
{
  static int searchList[MAX_NUM] = {0};
  static int primeList[MAX_NUM] = {0};
  
  double sqMaxVal = sqrt((double)maxVal) + 1;
  
  for (int i = 2; i <= sqMaxVal; i++) {
    if (searchList[i] == 0) {
      searchList[i] = 1;
      primeList[i] = 1;
      for (int j = i + 1; j <= maxVal; j++) {
        if (j % i == 0) {
          searchList[j] = 1;
        }
      }
    }
  }
  
  for (int i = 2; i <= maxVal; i++) {
    if (searchList[i] == 0) {
      primeList[i] = 1;
    }
  }
  
  int count = 0;
  for (int i = 2; i <= maxVal; i++) {
    if (primeList[i] == 1) {
      count++;
    }
  }
  
  return count;
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		long int i;
		int number[100000]={0};
		int ans=0;

		for(i=2;i<n;i++){
			if(number[i]==0){
				ans++;
				for(m=i;m<n;m+=i){
					number[m]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e6+5;
int is_prime[N];

int prime(int n)
{
	for(int i = 0;i <= n;++i)	
		is_prime[i] = true;
	is_prime[0] = 1;is_prime[1] = false;
	int res = 0;
	for(int i = 2;i <= n;++ i)
	{
		if(is_prime[i])
		{
			++res;
			for(int j = i * 2;j <= n;j += i)
				is_prime[j] = false;
		}
	}
	return res;
}

int main()
{
	int n;
	while(cin >> n)	
		cout << prime(n) << 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>

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 number[1000000];

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


int main() {
  int n, count;

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