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 <vector>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long Int;

const int N = 1000000;
const int M = 1000;
const int K = 6000000;

vector<Int> iterativeSieve(){
    static int p[K], table[M];
    for(int i=2; i<M; i++) p[i] = i;
    for(int i=2; i*i<M; i++){
        if(p[i]){
            for(int j=i*i; j<M; j+=i){
                p[j] = 0;
            }
        }
    }
    p[0] = p[1] = 0;
    int num = remove(p, p+M, 0) - p;
    for(int m=M; m<N; m+=M){
        for(int x=m; x<m+M; x++){
            table[x-m] = x;
        }
        for(int i=0,j; p[i]*p[i]<m+M; i++){
            if(p[i] >= m)          j = p[i] * p[i];
            else if(m % p[i] == 0) j = m;
            else                   j = m - (m % p[i]) + p[i];
            for(; j<m+M; j+=p[i])  table[j-m] = 0;
        }
        num = remove_copy(table, table+M, p+num, 0) - p;
    }
    return vector<Int>(p, p+num);
}

int main(){
    vector<Int> prime = iterativeSieve();
    int n, cnt;

    while(cin >> n){
        cnt = 0;
        for(int i=0; prime[i] <= n && i < prime.size(); i++){
            cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
long long gcd(long long a,long long b){if(a%b==0){return b;}else return gcd(b,a%b);}
long long lcm(long long a,long long b){if(a==0){return b;} return a/gcd(a,b)*b;}
long long MOD; template<class T> void mod(T &n){MOD=n;}
#define sym cout<<"---------"<<endl;
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl
#define WHITE 1
#define BLACK 2
#define GRAY 1
#define RE return 0
#define int ll

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

bool prime[1000005]={true};

signed main(){
  int n;
  while(cin>>n){
    if(n==1){cout<<0<<en; RE;}
    int ans=0;
    for(int i=2; i<=n; i++){
      if(isprime(i)&&prime[i]) {
        ans++;
        for(int j=i; j<=n; j+=i) prime[j]=false;
      }
    }
    cout<<ans<<en;
  }
}

C++: #include <iostream>

using namespace std;
int prime(int n){ 
        bool* notprime = new bool[n+1];
        int counter = 0;
        for(int i = 2 ; i <= n ; i++){ 
                if(!notprime[i]){
                        counter++;
                        for(int j = 2 ; j*i <= n ; j++){
                                notprime[j*i] = true;
                        }   
                }   
        }   
        return counter;
}
int main(){
        int n;
        while(cin >> n){ 
                cout << prime(n) << endl;
        }   
}

C++: import math

while True:
    try:
        n = int(input())
        c = [1 for i in range(n)]
        c[0] = 0
        i = 2
        while i**2 <= n:
            j = i*2
            while j <= n:
                c[j - 1] = 0
                j += i
            i += 1
        print(sum(c))
    except:
        break

C++: #include <iostream>
using namespace std;
char s[1000004];
int  d[1000004];
int main( void )
{
  int M=1000000;
  int n=0;
  for( int i=2; i<M; i++ ){
    if( !s[i] ){
      int j=i*2;
      while( j < M ){ s[j]=1; j+=i; }
      n++;
    }
    d[i] = n;
  }
  while( 1 ){
    cin >> n;
    if( cin.eof() ) break;
    cout << d[n] << endl;
  }
  return 0;
}

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

int main()
{
	long int n,m;
	while(cin>>n){
		long int i;
		int number[10000000]={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 <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt, minID, min=1;
    int list[100000];

    cnt=0;
    for (int i=0; i<1000000; i++){
        if (i%10==0) list[i/10] = cnt;
        cnt += IsPrime(i);
    }
    while (scanf("%d", &n) && n!=EOF){
        cnt = list[n/10];
        for (int i=1; i<n%10; i++){
            cnt += IsPrime(i);
        }
        printf("%d\n", cnt);
    }
    return 0;
}

inline int IsPrime(int n){
    int i;

    for (i=2; i*i<=n; i++){
        if (n%i==0) return 0;
    }
    return 1;
}

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

using namespace std;

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

	return true;
}

int main()
{
	int N[3] = { 0, 0, 0 };
	int C[3] = { 0, 0, 0 };

	cin >> N[0] >> N[1] >> N[2];

	for (int i = 0; i < 3; i++)
	{
		for (int j = 2; j <= N[i]; j++)
		{
			if (isprime(j) == true)
			{
				C[i] += 1;
			}
		}
	}

	cout << C[0] << endl << C[1] << endl << C[2] << endl;

	return 0;
}

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

int main(){

	int n, i, j, prmnum;
	bool prm = true;
	double sqrootm,sqrootp;

	while(cin>>n){
		if(n==0)prmnum=0;
		else if(n==1)prmnum=0;
		else if(n==2)prmnum=1;
		else{

			prmnum = 2;

			for( i=6; i<=n+1; i+=6 ){
				prm = true;

				sqrootm = sqrt((double)(i-1));
				sqrootp = sqrt((double)(i+1));

				for( j=3;j<=sqrootm;j+=2 ){
					if( (i-1)%j == 0 ){
						prm = false;
						break;
					}
				}
				if(prm)prmnum++;

				prm = true;

				if( i!=n+1 ){
					for( j=3;j<=sqrootp;j+=2 ){
						if( (i+1)%j == 0 ){
							prm = false;
							break;
						}
					}
				}
				if(prm)prmnum++;
			}
		}






		cout << prmnum << endl;


	}
	return 0;
}

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

#define MAX_N 2000000
int prime[MAX_N];



int main(){
	prime[1] = 1;
	prime[2] = 0;
	prime[3] = 0;
	for(int i = 2; i<=MAX_N;i++){
		if(prime[i] == 0)
			for(int j=2*i;j<=MAX_N;j=j+i)
				prime[j] = 1;
	}
	
	int n;
	int num=0;
	while(cin.eof()==0){
		cin >> n;	
		for(int k = 1;k<=n; k++){
			if(prime[k]==0)
				num++;
		}
		cout << num << endl;
		num = 0;
	}
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) { prime[length] = p; length++; return; }
int main(){
	insert(2);
	for (ll i = 3; i < 1000000; i += 2) {
		for (ll j = 0; j < length; j++)
			if (i%prime[j] == 0)goto cont;
			else if (prime[j] > sqrt(i))break;
		insert(i);
	cont:;
	}
	ll n; while (cin >> n) {
		ll ans = 0;
		while (prime[ans] <= n&&ans < length) {
			ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() 
{
  int a=999999;
  bool list[a+1];
  memset(list,true,sizeof(list));
  list[1]=false;
  for(int i=4;i<=a;i=i+2)
  {
    list[i]=false;
  }
  for(int i=3;i*i<=a;i=i+2)
  {
    if(list[i]==true)
    {
      for(int k=i*i;k<=a;k=k+i+i)
      {
        list[k]=false;
      }
    }
  }
  int temp;
  while(scanf("%d",&temp))
  {
    int count=0;
    for(int i=1;i<=temp;i++)
    {
      if(list[i]==true)
      {
        count++;
      }
    }
    printf("%d\n",count);
  }
  
}