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] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

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

C++: #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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

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();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//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())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second.first
#define T4 second.second.second

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

char bits[1000000];
LL primes[100000], n_primes; 
int cnt[1000000];

void sieve(){
	int i, j;
	memset(bits, 1, 1000000);
	bits[0] = bits[1] = 0;
	for (i = 0; i < sqrt(1000000.0)+1; i++)
		if (bits[i])
			for (j = i * i; j < 1000000; j += i)
				bits[j] = 0;
	for (i = j = 0; i < 1000000; i++)	
		if (bits[i]) primes[j++] = i;
	n_primes = j;
}

int main(){
	sieve();
	FOR(i,1,1000000){
		cnt[i] = cnt[i-1];
		if(bits[i])cnt[i]++;
	}
	int n;
	while(cin>>n)cout << cnt[n] << endl;
	return 0;
}

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

using namespace std;

class Prime {
private:
  vector<long long> divisor;
  
public:
  Prime(long long n) {
    for (long long i = 0; i < n; ++i) divisor.emplace_back(i);
    for (long long i = 2; i <= n / i; ++i) if (divisor[i] == i) {
      for (long long j = i * i; j < n; j += i) divisor[j] = i;
    }
  }
  
  bool isPrime(long long n) {
    if (n <= 1) return false;
    if (n < (long long)divisor.size()) return divisor[n] == n;
    for (long long i = 2; i <= n / i; ++i) if (n % i == 0) return false;
    return true;
  }
  
  vector<long long> factor(long long n) {
    vector<long long> res;
    for (long long i = 2; i <= n / i && n >= (long long) divisor.size(); ++i) {
      while (n % i == 0) {
        res.emplace_back(i);
        n /= i;
      }
    }
    if (n >= (long long)divisor.size()) {
      res.emplace_back(n);
    } else {
      while (n > 1) {
        res.emplace_back(divisor[n]);
        n /= divisor[n];
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
  
  vector<long long> divisors(long long n) {
    vector<long long> res;
    for (long long i = 2; i <= n / i && n >= (long long) divisor.size(); ++i) {
      if (n % i) continue;
      res.emplace_back(i);
      while (n % i == 0) n /= i;
    }
    if (n >= (long long)divisor.size()) {
      res.emplace_back(n);
    } else {
      while (n > 1) {
        long long d = divisor[n];
        res.emplace_back(d);
        while (n % d == 0) n /= d;
      }
    }
    sort(res.begin(), res.end());
    return res;
  }
};

int main() {
  Prime prime(1000000);
  array<int, 1000000> sum;
  sum[0] = 0;
  for (int i = 1; i < 1000000; ++i) sum[i] = sum[i - 1] + prime.isPrime(i);
  int n;
  while (cin >> n) cout << sum[n] << endl;
}

C++: #include <iostream>
using namespace std;
 
bool isprime(int n) { //??´????°?????????°true
    for(int i=2; i*i <= n; i++) {
        if(n%i==0) return false;
    }
    return n != 1;
}
 
int main() {
int n;
while(cin >> n) {
int cnt = 0;
for(int i=2; i<=n; i++) if(isprime(i)) cnt++;
cout << cnt << endl;
}
return 0;
}

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

bool isPrimeNumber(const unsigned long n);

int main(){
    unsigned long n;
    while(cin>>n){
        unsigned ans = 0;
        for(unsigned long i=n;i>0;i--){
            if(isPrimeNumber(i)){
                ans++;
            }
        }
        cout << ans << endl;        
    }
}

bool isPrimeNumber(const unsigned long n){
    static const unsigned long carn[]{
        561,	1105,	1729,	2465,	2821,	6601,	8911,
        10585,	15841,	29341,	41041,	46657,	52633,	62745,	63973,	75361,
        101101,	115921,	126217,	162401,	172081,	188461,	252601,	278545,	294409,
        314821,	334153,	340561,	399001,	410041,	449065,	488881,	512461,	530881,
        552721,	656601,	658801,	670033,	748657,	825265,	838201,	852841,	997633,
        1024651,1033669,1050985,1082809,1152271,1193221,1461241,1569457,1615681,
        1773289,1857241,1909001,2100901,2113921,2433601,2455921,2508013,2531845,
        2628073,2704801,3057601,3146221,3224065,3581761,3664585,3828001,4335241,
        4463641,4767841,4903921,4909177,5031181,5049001,5148001,5310721,5444489,
        5481451,5632705,5968873,6049681,6054985,6189121,6313681,6733693,6840001,
        6868261,7207201,7519441,7995169,8134561,8341201,8355841,8719309,8719921,
        8830801,8927101,9439201,9494101,9582145,9585541,9613297,9890881
    };

    if(n==2)
        return true;
    else if(n<2||n%2==0)
        return false;
    else{
        for(unsigned long i=0;i<sizeof(carn)/sizeof(carn[0]);i++){
            if(n<carn[i])
                break;
            if(n==carn[i])
                return false;
        }
        for(unsigned long i=n-1;i>0;i--){
            if(fmodl(powl(i,n),n)!=i)
                return false;
        }
        return true;
    }
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

bool t[1000000];

int main(){
	memset(t,1,sizeof(t));
	t[0] = t[1] = false;
	for(int i = 2; i < 1000; i++){
		if(t[i])
			for(int j = 2 * i; j < 1000000; j += i){
				t[j] = false;
			}
	}

	int n;
	while(cin>>n){
		int ans = 0;
		for (int i = 0; i <= n; i++)
		{
			ans += t[i];
		}
		cout << ans << endl;
	}

	return 0;
}