Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

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)
	{
		int c = 0;

		for (int i = 2; i <= n; i++)
		{
			if (isprime[i] == true)
			{
				c++;
			}
		}

		cout << c << endl;
	}

	return 0;
}

C++: /*
 * main.cpp
 *
 *  Created on: 2011/04/08
 *      Author: satoki
 *      5:09 ~ 6:03
 *      Wrong Answer : 2
 *      nÈºÌfð¢ÅÀ
 *      Runtime Error : 4
 *      PÂ½ßÉfðZbg
 */
#include <iostream>
#define MAX_iP 1000000 // 664,580 ÔÚÌf = 10,000,019
#define MAX_nP 78498 // ÔºÌÓ¡àßÄ (KvÈfÌ + 1) ðmÛ
using namespace std;

int iN;

// fe[u
bool bPrime[MAX_iP];
int iPrime[MAX_nP];
int nPrime;

void setPrime() {
  // fe[uðì¬
  int i, j;

  nPrime = 0;
  fill(bPrime, bPrime + MAX_iP, true);
  bPrime[0] = bPrime[1] = false;

  for (i = 2; i < MAX_iP; i++) {
    if (bPrime[i]) {
      iPrime[nPrime++] = i;
      for (j = 2; i * j < MAX_iP; j++) {
        bPrime[i * j] = false;
      }
      //if (nPrime == MAX_nP) break;
    }
  }
  //printf("nPrime = %d i = %d\n", nPrime, i);
}

void init() {
  setPrime();
}

bool input() {
  if (scanf("%d", &iN) == EOF) return false;
  return true;
}

int manage() {
  int i;
  for (i = 0; iPrime[i] <= iN; i++);
  return i;
}

int main() {
  init();
  while (1) {
    if (!input()) break;
    printf("%d\n", manage());
  }
  return 0;
}

C++: #include <stdio.h>

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(int i=2;i<m;i++){
				if(i!=m && m%i==0){
					check=false;
					break;
				}
			}
			if(check==true){
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

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

using namespace std;

int main() {
	bool a[1000000] = {1,1};
	int n, i, j, f = 0, count = 0;
	while (cin >> n) {
		f = 0;
		count = 0;
		while (f <= ceil(sqrt(n))) {
			i = f + 1;
			while (a[i] == 1) {
				i++;
			}
			f = i;
			for (j = i + 1; j <= n; j++) {
				if (j % f == 0) a[j] = 1;
			}
		}
		for (i = 0; i <= n; i++) {
			if (a[i] == 0) { count++;}
		}
		cout << count << endl;
	}
}

C++: #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
 
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
const int INF = 100000000;
const double EPS = 0.0000001;
typedef pair<int,int> P;

int n;
//           999999
bool isPrime[1000003];

void solve() {
	int ans=0;
	rep(i,n+1) if(isPrime[i]) ans++;
	cout<<ans<<endl;
}

void init() {
	rep(i,1000003) isPrime[i]=true;
	isPrime[0]=isPrime[1]=false;

	for(int i=2;i<1000003;i++) {
		if(isPrime[i]) {
			for(int j=i+i;j<1000003;j+=i) isPrime[j]=false;
		}
	}


}

int main() {
	init();
	while (cin>>n)
	{
		if(n==0) return 0;
		solve();

	}
}

C++: #include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
int prime[999999];
void reshan(int input)
{
	int i,j;
	int flag=0;
	for(i=2;i<=input;i++)
	{
		if(prime[i]==0)
		{
			flag++;
		}
	}
	printf ("%d\n",flag);
}
int main ()
{
    int input,i,j;
    memset(prime,0,sizeof(prime));
	prime[0]=prime[1]=1;
	for(i=2;i<999999;i++)
	{
		if(prime[i]==0)
		{
			for(j=i+i;j<999999;j+=i)
			{
				prime[j]=1;
			}
		}
	}
   while(scanf("%d",&input)!=EOF)
   {
       reshan(input);
   }
   return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N;
//??¨????????????????????????
bool is_prime[ 10000 + 1 ];
vector<int> P;
int E( const int N )
{
    int cnt{};
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//?????????
    }    
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            cnt++;
        }
    }
    return cnt;
}
int main()
{
    while( cin >> N )
    {
        cout << E( N ) << endl;
    }
    return 0;
}

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

int setPrimeNumberCount(int n) {
    int count = 0;
    bool primeFlag = true;
    
    if(n >= 2) {
        count++;
    }
    
    for(int i = 3; i <= n; i+=2) {
        for(int j = 3; j < i; j+=2) {
            if(i % j == 0) {
                primeFlag = false;
            }
        }
        if(primeFlag) {
            count++;
        }
        primeFlag = true;
    }
    
    
    return count;
}

int main(void) {
    int n;
    int count = 0;
    
    while(cin >> n) {
        count = setPrimeNumberCount(n);
        cout << count << endl;
        count = 0;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

const int N = 1000000;

int num[N];

void init() {
	num[0] = num[1] = 0;
	for (int i=2; i<N; ++i) num[i] = 1;
	for (int i=2; i<1000; ++i) {//素数&#31579;&#36873; 
		if (num[i * i]) {
			int j = i + i;
			for (;j < N; num[j] = 0, j += i); 
		}
	}
	for (int i=1; i<N; ++i) num[i] += num[i-1];
}

int main() {
	int n;
	init();
	while (scanf("%d", &n) != EOF) {
		printf ("%d\n", num[n]);
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  
  while(!cin.eof()) {
    cin >> n;
    list<int> search_list;
    list<int> prime_number;
    while(n>=2) {
      if(n%2 != 0) 
	search_list.push_front(n);
      n--;
    }
    if(!search_list.empty())
      prime_number.push_front(2);
    while(!search_list.empty()) {
      int m = search_list.front();
      prime_number.push_back(m);
      search_list.pop_front();
      list<int>::iterator it = search_list.begin();
      while(it!=search_list.end()) {
	if((*it % m) == 0){
	  it = search_list.erase(it);
	  continue;
	}
	it++;
      }				   
    }
    cout << prime_number.size() << endl;
    prime_number.clear();
    search_list.clear();
  }
  return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> primes;
  int i, j, n;
  while (cin >> n) {
    primes.reset();
    for (i = 2; i <= n; i++)
      if (primes[i] == false)
	for (j = i + i; j <= n; j += i)
	  primes[j] = true;
    cout << n - primes.count() - 1 << endl;
  }
}