Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func check(n int) int {
	eratos := make([]bool, n+1)
	cnt := 0
	for i := 2; i < len(eratos); i++ {
		if !eratos[i] {
			cnt++
			for j := i*i; j < len(eratos); j += i {
				eratos[j] = true
			}
		}
	}
	return cnt
}

func main() {
	for scanner.Scan() {
		n := nextInt()
		fmt.Println(check(n))
	}
}

C++: LIMIT = 10000000
 
isPrime = [True for _ in range(LIMIT)]

isPrime[0] = isPrime[1] = False
 
for i in range(2, int(LIMIT ** 0.5)+1):
  if isPrime[i]:
    for j in range(i * i, LIMIT, i):
      isPrime[j] = False
 
try:
    while True:
        n = int(input())
        count = 0
        for i in range(n+1):
            if isPrime[i]:
                count += 1
        print(count)
except EOFError:
  pass

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

using namespace std;

int main(int argc, const char *argv[])
{
    int N=100000;
    //cin >> N;
    bool mark[100000];
    memset(mark,true,100000);

    mark[0]=mark[1]=false;
    for(int i=4;i<N;i+=2)
        mark[i]=false;
    for(int i=3;i*i<=N;i+=2)
    {
        if(mark[i]==true)
        {
            for(int j=i*i;j<N;j+=i*2)
            {
                mark[j]=false;
            }
        }
    }

    int n;
    int cnt;
    while(scanf("%d",&n)==1)
    {
        cnt=0;
        for(int i=0;i<=n;i++)
        {
            if(mark[i]==true)
                cnt++;
        }
        cout << cnt << endl;
    }




    return 0;
}

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

int main()
{
	int n;
	const int MAX = 1000000;
	int primecount[MAX];

	for (int i = 2; i < MAX; i++) {
		primecount[i] = 1;
	}

	for (int i = 2; i < MAX; i++) {
		if (primecount[i] == 1) {
			for (int j = i * 2; i < MAX; j += i) {
				primecount[j] = 0;
			}
		}
	}

	for (int i = 1; i < MAX; i++) {
		primecount[i] += primecount[i - 1];
	}

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

	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;

template <typename T>
vector<bool> eratosthenes(T n) {
	vector <bool> IsPrime;
	if (n + 1 > IsPrime.size()) {
		IsPrime.resize(n + 1, true);
	}
	IsPrime[0] = false;
	IsPrime[1] = false;

	for (T i = 2; i*i <= n; i++) {
		if (IsPrime[i]) {
			for (T j = 2; i*j <= n; j++) {
				IsPrime[i*j] = false;
			}
		}
	}
	return IsPrime;
}

int main() {
	vector<bool> isPrime = eratosthenes(1LL << 20);
	vector<ll> numPrime((1LL << 20) + 1, 0);
	ll now = 0;
	for (ll i = 1; i <= (1LL << 20); i++) {
		if (isPrime[i] == true) {
			now++;
		}
		numPrime[i] = now;
	}

	ll n;
	n = -1;
	while (true) {
		cin >> n;
		if (n == -1)break;
		cout << numPrime[n] << endl;
		n = -1;
	}


}

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

int main()
{
	vector<int> pcount;
	int prime[10000];
	int j, k, x, num,count=0;
	while (cin >> num){
		prime[0] += 2;
		x = 1;
		k = 1;
		while (prime[k-1] <= num)
		{
			x += 2;
			j = 0;
			while (j < k && x % prime[j] != 0)j++;
			if (j == k)
			{
				prime[k++];
				count++;
			}
		}
		pcount.push_back(count);
		count = 0;
	}
	for (int i = 0; i < pcount.size(); i++)
	{
		cout << pcount[i] << endl;
	}
	return 0;
}

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

bool isprime(int n){
    if(n==0 || n==1){
        return false;
    }
    if(n==2){
        return true;
    }
    for(int i=2;i<n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

int solve(int x){
    int m = 0;
    for(int i=0;i<=x;i++){
        if(isprime(i)){
            m++;
        }
    }
    return m;
}
int main(){
    int n;
    cin >> n;
    cout << solve(n) << endl;
    return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = 998244353;
const double EPS = 1e-9;

bool s[1000000] = {};
int sosu[1000000] = {};
void erast(){
  memset(s,1,sizeof(s));
  s[1] = false;
  s[0] = false;
  REP(i,2,1000){
    if(s[i]){
      REP(j,2,1000000){
        if(i*j>=1000000) break;
        s[i*j] = false;
      }
    }
  }
  REP(i,2,1000000) sosu[i] = sosu[i-1]+s[i];
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    erast();
    int n;
    while(cin >> n,n){
      cout << sosu[n] << endl;
    }
    return 0;
}

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

using namespace std;
const int N=999999;
bool isprime[N+1];
int sum[N+1];

int main()
{
    memset(isprime,true,sizeof(isprime));
    for(int i=2;i<N/2;i++)
        for(int j=2*i;j<N;j+=i)
            if(isprime[i]) isprime[j]=false;
    isprime[0]=isprime[1]=false;
    memset(sum,0,sizeof(sum));
    for(int i=2;i<N;i++)
    sum[i]=sum[i-1]+isprime[i];

    int n;
    while(cin>>n)
    {
        cout<<sum[n]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <math.h>

using namespace std;

int SUUZI[1000000];

int a=0,b,d,f,n,c=0;
double buffer;

int main(){

	for(d=0;d<1000000;d++){SUUZI[d]=1;};
	
		for(a=3;a<1000000;a++){
			buffer=a;
				for(b=2;1;b++){
					if(a%b==0){SUUZI[a]=0;break;};
					if(b>sqrt(buffer)){SUUZI[a]=1;break;};
				};
};


while(cin>>n){
	c=0;
for(d=0;d<=n;d++){c+=SUUZI[d];};

cout<<c-2<<endl;

};
return 0;

}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-8;
typedef long long ll;

const int SIZE = 1000001;
bool is_prime[1000001];
vector<int> primes;
int main()
{
	fill(is_prime, is_prime+SIZE, true);
	for (int i = 2; i < SIZE; ++i)
	{
		if (is_prime[i])
		{
			for (int j = 2*i; j < SIZE; j += i)
				is_prime[j] = false;
			primes.push_back(i);
		}
	}

	int n;
	while (scanf("%d", &n) != EOF)
		printf("%d\n", upper_bound(primes.begin(), primes.end(), n) - primes.begin() - 1);

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

constexpr int N = 999999;
vector<bool> primes( N+1, true );

void make_table() {
	primes[0] = false;
	primes[1] = false;

	int nr = (int)sqrt( N );
	for( int i = 2; i <= nr; ++i ) {
		if( primes[i] ) {
			for( int j = i+i; j <= N; j += i ) {
				primes[j] = false;
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio( false );

	make_table();

	int n;
	while( cin >> n ) {
		cout << count( primes.begin()+1, primes.begin()+1 + n, true ) << endl;
	}
}