Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#define maxn 1000000
using namespace std;
int prime[maxn],number[maxn];
void getprime()
{
    int m=sqrt(maxn+0.5);
    for(int i=2;i<=m;i++)
    {
        if(!prime[i])
        {
            for(int j=i+i;j<maxn;j+=i)
            {
                prime[j]=1;
            }
        }
    }
    int sum = 0;
    for(int i=2;i<maxn;i++)
    {
        if(!prime[i])
        {
            sum++;
        }
        number[i]=sum;
    }
}
int main ()
{
    int n;
    getprime();
    while(scanf("%d",&n)!=EOF)
    {
        printf("%d\n",number[n]);
    }
}
/**
--------------------- 
???zhaiqiming2010 
???CSDN 
???https://blog.csdn.net/zhaiqiming2010/article/details/62281598 
?????????????????????????
**/

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

int main(){

	const int N_MAX=1000000;
	int i,j,n[32],ni,soi,max;
	int so[N_MAX],count[N_MAX];
	
	for(i=0;i<N_MAX;i++)
		count[i]=so[i]=0;
	ni=0;
	max=0;
	while(cin>>n[ni])
		if(n[ni++]>max)
			max=n[ni-1];
	int sq_max = (int)sqrt(max);
	so[0]=so[1]=1;
	for(soi=0,i=2;i<=sq_max;i++){
		if(so[i]>0)continue;
		for(j=i*2;j<=max;j+=i)
			so[j]=1;
	}
	for(i=2;i<=max;i++){
		count[i] = count[i-1]+1-so[i];
	}
	for(i=0;i<ni;i++)
		cout << count[n[i]] << endl;

	return 0;
}

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n)) {
		res = 0;
		while (!Eratos[n]) {
			n--;
		}
		printf("%d\n",Eratos[n]);
	}
	return 0;
}

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

template<typename T>
struct Sieve{
    vector<bool> is_prime;
    vector<T> prime;
    T prime_count;
    Sieve(T n):is_prime(n+1,true),prime_count(0){
        is_prime[0] = false;
        is_prime[1] = false;
        for (T i=2;i<=n;i++){
            if (is_prime[i]){
                prime.push_back(i);
                prime_count++;
                for (T j=2*i; j<=n ;j+=i) is_prime[j]=false;
            }
        }
    };
};

int main(){
    ll max_n = 1000000;
    ll n;
    Sieve<ll> a(max_n);
    vector<ll> prime_count(max_n,0);
    ll count = 0;
    for (ll i=0;i<max_n;i++){
        if (a.is_prime[i]) count++;
        prime_count[i] = count;
    }
    while(scanf("%lld",&n)==1){
        ll c= prime_count[n];
        printf("%lld\n", c);
    }
}

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