Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

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

int main(){
  int a;
  int i, j;
  int past=1, a_sqrt;
  int count;
  bool chk[1000000];

  for(i=1; i<1000000; i++) chk[i]=true;
  while(cin >> a){
    count=0;
    if(past>=a){
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
    else {
      a_sqrt=(int)sqrt(a);
      for(i=2; i<=a_sqrt; i++){
        for(j=past+1; j<=a; j++){
          if(j%i==0) chk[j]=false;
        }
      }
      past=a;
      for(i=1; i<=a; i++){
        if(chk[i]) count++;
      }
      printf("%d\n", count);
    }
  }

  return 0;
}

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

int Prime[1000000];

int main() {
	for(int i=0;i<1000000;++i)Prime[i]=1;
	
	Prime[0]=0;
	Prime[1]=0;
	
	for(int i=2;i<1000000;++i){
		if(Prime[i]){
			for(int j=i*2;j<1000000;j+=i){
				Prime[j]=0;
			}
		}
	}
	
	int n,cnt;
	while(cin>>n){
		cnt = 0;
		for(int i=0;i<=n;++i){
			cnt+=Prime[i];
		}
		cout<<cnt<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int box[1000005];
int main()
{
	for(int i=0;i<=999999;i++)
		box[i]=1;
	box[1]=box[0]=0;
	int n;
    int rooted=sqrt(999999);
    for(int i=2;i<=rooted;i++)
        if(box[i])
            for(int j=2;j*i<=999999;j++)
                box[j*i]=0;
	while (cin >> n)
	{
		int s=0;
		for (int i=1;i<=n;i++)
			s+=box[i];
		cout << s << endl;
	}
}

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){
chack=false;
}
}
if(check==true){
count++;
}
}
}
return 0;
}

C++: #include<iostream>
#include<string>
#include<new>
int main(){for(int m,n,o,c,d,e,i;!(std::cin>>n).eof();){if(n<3)e=n>1;else{bool*v=new bool[c=(n&1?n:--n)/2+1];memset(v,1,c);for(i=m=e=1;i<c;i++){for(m=i;m<c&&!v[m];)m++;if(m==c)break;e++;for(d=o=m*2+1;d<n+1;d+=o*2)v[d/2]=0;if(n<o*o)break;}for(i=1;i<c;)e+=v[i++];delete[]v;}printf("%d\n",e);}}

C++: #include<iostream>
using namespace std;
bool b[1000005];
int s[1000005];
int main(){
	int i,j,k;
	int n;
	b[i]=true;
	for(i=2;i<1000000;i++){
		if(b[i]==false){
			for(j=2*i;j<1000000;j+=i){
				b[j]=true;
			}
			s[i]=s[i-1]+1;
		}else{
			s[i]=s[i-1];
		}
	}
	while(cin>>n){
		cout<<s[n]<<endl;
	}
	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) {
		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 <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
long long ll;

const int N = 1000000;
bool prime[N];
int cnt[N];

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

void setPrime(int n) {
	int i, j;
	prime[0] = prime[1] = false;
	for (i=2; i<=n; i++) prime[i] = true;

	for (i=2; i<=n; i++) {
//		if (isPrime(i)) prime[i] = true;
		if (prime[i])
			for (j=i*2; j<=n; j+=i) prime[j] = false;
	}
}

int main() {
	int i, j;
	int n;

	setPrime(N);

	for (i=2; i<N; i++) {
		cnt[i] = cnt[i-1];
		if (prime[i]) cnt[i]++;
	}

	while (scanf("%d ", &n) != EOF) {
		printf("%d\n", cnt[n]);
	}

	return 0;
}

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

C++: #include <iostream>
#include <bitset>
#include <fstream>

using namespace std;

#define NUM_LIMIT 1000000   // numbers < NUM_LIMIT

int getNumOfPrimes(bitset<NUM_LIMIT> &isPrime, int min, int max){
    int cnt = 0;
    for (int i = 2; i <= max; i++){
        if (!isPrime[i]) continue;  // skip non prime numbers
        cnt ++;
        if (i >= min){
            // cross out the multiples of the number
            for (int j = 2; i*j <= max; j++){
                isPrime[i*j] = 0;
            }
        }
    }
    return cnt;
}

int main(){
    //ifstream cin("input.txt");
    bitset<NUM_LIMIT> isPrime;
    isPrime.set();  // set all bits to 1
    
    // input data
    int number;
    int max_num = 0;
    while(cin >> number){
        int cnt = 0;
        if (number > max_num){
            cnt = getNumOfPrimes(isPrime, max_num+1, number);
            max_num = number;
        } else {
            cnt = getNumOfPrimes(isPrime, number+1, number);
        }
        cout << cnt << endl;
    }
    return 0;
}

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

#define N 999999+1
int prime[N];
void sieve(int en) {
  // prime[prime number] = 0
  // prime[not prime number] = 1
  for(int i=2;i<=(int)sqrt(en);i++) {
    for(int j=i*2;j<=en;j+=i) {
      prime[j] = 1;
    }
  }
}

int main() {
  int n;
  int max_n = 2;
  while(cin >> n) {
    if(n > max_n) {
      sieve(n);
    }
    int cnt = 0;
    for(int i=2;i<=n;i++) {
      if(prime[i] == 0)
        cnt++;
    }
    cout << cnt << endl;
  }
}

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

int a[999999]={};

int main(){
	int n,ans=0;
	for(int i = 2; i*i < 999999; i++){
		for(int j = 0; j < 999999; j+=i){
			if(i!=j) a[j]=1;
		}
	}
	while(cin >> n){
		for(int i = 2; i <= n; i++){
			if(a[i]==0) ans++;
		}
		cout << ans << endl;
		ans=0;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int data[999999] = { -1 };
bool notprime[999999] = { false };

int main(int argc, char **argv){
	int n;
	int cnt;
	while (cin >> n) {
		cnt = 0;
		for (int i = 2; i < n; i++) {
			if (!notprime[i]) {
				cnt++;
				for (int j = 2; j <= n / i; j++) {
					notprime[i * j] = true;
				}
			}
			if (i >= sqrt(n)) {
				for (int k = i + 1; k <= n; k++) {
					if (!notprime[k]) {
						cnt++;
					}
				}
				break;
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

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

int main(){
	int n;
	
	while(scanf("%d",&n)==1){
	int count=0;
	double sqrtn = n;
		for(int i=3;i<=n;i+=2){
			bool p=true;
			for(int j=3;j<sqrt(sqrtn);j++){
				if(i % j == 0){
					p=false;
					break;
				}
			}
			if(p) count++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}