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<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

# define inOut(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
# define RESET(a) memset(a,0,sizeof(a))
# define MEMO(a) memset(a,-1,sizeof(a))
# define DEBUG puts("Debug-Has-Come-Until-Here")


typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define MAXPRIME 1000000

bitset<MAXPRIME+1> boolPrime(0);
int prefPrime[1000001] ={};

void sieve(int n){
	int i,j;
	boolPrime[1] = 1;
	for (i=2; i<=sqrt(n); i++){
		if (boolPrime[i] == 0)
		for (j=2*i; j<=n; j+=i){
			boolPrime[j] = 1;
		}
	}
}

int main(){
	cin.tie(NULL);
	
	int i,j,n = 0;
	sieve(MAXPRIME);
	for (i=1; i<=MAXPRIME; i++){
		n += !boolPrime[i];
		prefPrime[i] = n;
	}
	while(scanf("%d", &n) != EOF){
		printf("%d\n", prefPrime[n]);
	}
	return 0;
}

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

// bool isPrime(unsigned int n);

int main()
{
    int n;
    while(cin>>n){
        vector<int> primeTable;
        if( n==1 ){ cout << "0" << endl; continue; }
        primeTable.push_back(2);
        vector<int>::iterator j;
        for(int i=3; i<=n; i+=2){
            for(j=primeTable.begin(); j!=primeTable.end(); j++){
                if(!(i%(*j))) break; 
                if( (*j)*(*j) >= i ) {j=primeTable.end();break;} 
            }
            if( j==primeTable.end() ) primeTable.push_back(i);
        }
        cout << primeTable.size() << endl;
    }
    

    return 0;
}

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

#define N 1000001

int main() {

	vector<bool> check(N, false);
	vector<long long> prime;
	
	
	for(long long i = 2; i < N; ++i){
		if(!check[i]) prime.push_back(i);
		for(long long j = 2; i * j < N; ++j){
			check[i * j] = true;
		}
	}
	
	int n;
	
	while(cin >> n){
		auto it = lower_bound(prime.begin(), prime.end() , n+1);
		
		cout << distance(prime.begin(), it) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	while (cin)
	{
		string tmpstr;
		int tmp;

		getline(cin, tmpstr);

		tmp = atoi(tmpstr.c_str());

		vector<int> prime;

		for (int i(2); i <= tmp; ++i)
		{
			for (vector<int>::iterator i2(prime.begin()), n2(prime.end()); i2 != n2; ++i2)
			{
				if ((i % *i2) == 0)
				{
					goto nx;
				}
			}

			prime.push_back(i);
		nx:;
		}

		cout << prime.size() << endl;

		//if (cin.eof()) { break; }
	}

	return 0;
}

C++: #include<iostream>
 
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int prime[n+1];
        for(int i=0;i<=n;i++)
            prime[i]=1;
            prime[0]=0;
            prime[1]=0;
        for(int i=2;i*i<=n;i++)
             if(prime[i]==1)
        {
            for(int j=2;j*i<=n;j++)
            prime[i*j]=0;
        }
        int c=0;
        for(int i=0;i<=n;i++)
        {
            if(prime[i]==1)
                c++;
        }
        printf("%d\n",c);
    }

}

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

long long int a[1000000];

int main(){

  long long int n;

  for(long long int i=2;i*i<1000000;i++){
    if(a[i]==0){
      for(long long int j=i+i;j<1000000;j+=i) a[j]=1;
    }
  }

  while(cin >> n){

    long long int count=0;

    for(long long int i=2;i<n;i++){
      if(a[i]==0) count++;
    }

    cout << count << endl;

  }
}

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

using namespace std;

int sosuu(int n);

int main(){
    int n=0;
    int num=0;
    int a[30][2]={0};
    int max=0;
    while(scanf("%d",&n)!=EOF){
        if(max<n){
            max=n;
        }
        a[num][0]=n;
        num++;
    }
    
    int b[max];
    int c[max];
    int so=0;
    for(int i=0; i<=max; i++){
        b[i]=i;
    }
    b[1]=0;
    
    for(int i=2; i<sqrt(max); i++){
        if(b[i]!=0){
            for(int j=2; j<=max; j++){
                if(i*j<=max){
                    b[i*j]=0;
                }else{
                    j=max;
                }
            }
        }
    }
    
    for(int i=0; i<=max; i++){
        if(b[i]!=0){
            c[so]=i;
            so++;
        }
    }
    
    

    for(int i=0; i<num; i++){
        for(int j=0; j<so; j++){
            if(c[j]<=a[i][0]){
                a[i][1]++;
            }else{
                j=so;
            }
        }
    }

    
    for(int j=0; j<num; j++){
        cout<<a[j][1]<<"\n";
    }
    
}

C++: #include <stdio.h>

int IsPrime(int n);

int main(void){
    int n, cnt;

    while (scanf("%d", &n) && n!=EOF){
        cnt=0;
        for (int i=2; i<n; i++){
            if (IsPrime(i)) cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}

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

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

using namespace std;

int Count(bool [], int, int);

int main() {
  const int N = 1000000;
  bool num[N];
  for (int i = 0; i < N; i++)
    num[i] = true;

  const int N_MAX = 999999;
  const double MAX = sqrt(N_MAX);
  for (int i = 2; i <= MAX; i++) {
    if (num[i]) {
      for (int j = i; i*j <= N_MAX; j++) {
        num[i * j] = false;
      }
    }
  }

  int data;
  while (cin >> data) {
    cout << Count(num, 2, data) << endl;
  }
}

int Count(bool data[], int begin, int end) {
  int count = 0;
  for(int i = begin; i <= end; i++)
    if (data[i])
      count++;

  return count;
}

C++: #include<iostream>
#include<math.h>
using namespace std;
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}
int main() {
  int n;
  int sum[1000000];
  sum[0]=0;
  sum[1]=0;
  sum[2]=1;
  for(int i=3;i<1000000;i++) {
    sum[i]=sum[i-1];
    if(IsPrime(i)) 
      sum[i]++;
 }
  while(cin>>n)
    cout<<sum[n]<<endl;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool prime(int n)
{
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int main()
{
    int n,c,i;
    while(scanf("%d",&n)!=EOF)
    {
        c=0;
        for(i=2;i<=n;i++)
        {
            if(prime(i))
                c++;
        }
        cout<<c<<endl;
    }
    return 0;
}