Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main() {
	const int MAX_V = 100000;
	int prime[MAX_V+1];
	int i, k, v;
	for(i = 2; i <= MAX_V; i++) {
		prime[i] = 1;
	}
	for(i = 2; i*i <= MAX_V; i++) {
		if(prime[i]) {
			for(k = 2 * i; k <= MAX_V; k += i) {
				prime[k] = 0;
			}
		}
	}
	for(i=0;i<30;i++){
		scanf("%d", &v);
		int count = 0;
		for(i=0;i<=v;i++){
			int isprime = prime[i];
			if(isprime) count ++;
		}
		printf("%d",count);
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main() {
	int n, count = 0;
	while(cin >> n) {
		for(int i = 2; i < n + 1; i++) {
			count++;
			for(int j = 2; j <= i / 2; j++) {
				if(i % j == 0) {
					count--;
					break;
				}
			}
		}
		cout << count << endl;
		count = 0;
	}

	return 0;
}

C++: #include <stdio.h>

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

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