Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include <stdio.h>

int main (void){
	int number, i, j, count=0, flag=0, d;
	
	while(scanf("%d", &number)!=EOF){
		count=0;
		int n[number];
		for(i=0; i<number; i++){
			n[i]=i+1;
		}
		
		n[0]=-1;
		for(i=0; i<number; i++){
			if(n[i]!=-1){
				d=i+1;
				for(j=d, flag=0; j<=number; j+=d, flag++){
					if(flag!=0){
						n[j-1]=-1;
					}
				}
			}
		}
	
		for(i=0; i<number; i++){
			if(n[i]!=-1){
				//printf("%d\n", n[i]);
				count++;
			}
		}
		printf("%d\n", count);
	}
	
	return 0;
}

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

bool isPrime(int);

int main() {
	int n, p;
	while (cin >> n) {
		p = 0;
		if (cin.eof())
			return 0;
		for (int i = 2; i <= n; i++) {
			if (isPrime(i))
				p++;
		}
		cout << p << endl;
	}
	return 0;
}

bool isPrime(int x) {
	for (int j = 2; j <= sqrt((double)x); j++) {
		if (x % j == 0)
			return false;
	}
	return true;
}

C++: #include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V+1],sum[MAX_V+2]={0};
int main(){
  int n;
  for(int i = 2;i <= MAX_V;i++){
    prime[i] = 1;
  }
  for(int i = 2;i * i <= MAX_V;i++){
    if(prime[i]){
      for(int k = 2* i;k <= MAX_V;k += i)
      prime[k]=0;
    }
  }
  for(int i = 2;i < MAX_V;i++){
    sum[i] +=sum[i-1]+prime[i];
  }
  for(int i = 0; i < 30; i++){
    scanf("%d",&n);
    printf("%d\n",sum[n]);
  }
  return 0;
}

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

using namespace std;

static const int MAX = 999999;

vector<bool> v(int(sqrt(MAX)), false);

using namespace std;

int main(){
    v[1] = true;
    for (size_t i = 2; i < v.size(); ++i){
        int flag = 0;
        if ((i+1) % 2 == 0) continue;
        for (size_t j = 3; j < i; ++j){
            if ((i+1)%j == 0) {flag = 1; break;}
        }
        if (flag != 1) v[i] = true;
    }
    
  
    int input;
    while (cin >> input){
     int count(0);
     for (int i = 0; i < input; ++i){count+=v[i]==true;}
     cout << count << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
	bool a[1000001];
	for(int i=1;i<=1000000;i++)a[i]=true;
	for(int i=2;i*i<=1000000;i++){
		for(int j=2;i*j<=1000000;j++){
			a[i*j]=false;
		}
	}
    int n;
	while(cin >> n){
		int ans=-1;
		for(int i=1;i<=n;i++){
			if(a[i])ans++;
		}
		printf("%d\n",ans);
	}
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999,a,b,c;
    char x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

int p[1000010];

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

C++: #include<stdio.h>

int pr[50847534];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
        /*printf("O\n");*/
      return nxp;
    }else{
        /*printf("X\n");*/
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF){
        printf("n=%d\n",n);
        i=0;
        if(n-1){
            while(pr[i]<=n){
                printf("prime:%d(%d)\n",pr[i],i+1);
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
    }
}

C++: #include<stdio.h>
#include<math.h>
int main(void)
{
	long long i,j,p,n,count;
	bool flag[1000000];
	while((scanf("%lld",&n)) != EOF)
	{
		p = (long long)sqrt((double)n);
		for(i = 3; i <= p; i = i + 2)
		{
			for(j = i * i; j <= n; j = j + 2 * i)
			{
				flag[j] = false;
				
			}
		}
		if(n == 1 || n == 0)
			count = 0;
		else
		{
			count = 1;
			for(i = 3; i <= n; i = i + 2)
			{
				if(flag[i])
					count++;
			}
		}
		printf("%lld\n",count);
	}

		
	return 0;
}

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

bool check(int in){
	for (int i = 3; i<=sqrt(in); i+=2){
		if (in % i == 0)
			return false;
	}
	return true;
}

int PrimeNumber(int in, int start){
	int count = 0;
	if (in > 2)	count++;
	for (int i = start; i <=in; i+=2){
		if (check(i))	count++;
	}

	return count;
}

int main(){
	int in, count500000 = PrimeNumber(500000, 3);

	while (cin >> in, !cin.eof()){
		if (in <= 500000)
			cout << PrimeNumber(in, 3) << endl;
		else
			cout << count500000 + PrimeNumber(in, 500001) << endl;
	}
}

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

C++: #include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <algorithm>

using namespace std;

bool isPrime(int n) {
	if (n == 2)return true;
	if (n < 2 || n % 2 == 0) return false;
	int i = 3;
	while (i <= sqrt(n)) {
		if (n%i == 0) return false;
		i = i + 2;
	}
	return true;
}

int main() {
	int a, count;
	vector<int> v;
	for (int i = 0; i <= 999999;i++) {
		if (isPrime(i)) v.push_back(i);
	}

	while (cin >> a) {
		count = 0;
		for (int i = 0; i <v.size()+1; i++) {
			if (v.size() + 1 == i) {
				count = i;
				break;
			}
			if (v[i] > a) {
				count = i;
				break;
			}
		}
		cout << count << endl;
	}
}

C++: //
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

int num_prime(int n){
	int counter = 0;
	for(int i=2; i<=n; i++){
		if(isPrime(i)) counter++;
	}
	return counter;
}


int main(){
	int n;
	while(cin >> n){
		cout << num_prime(n) << endl;
	}

	return 0;
}

C++: #include<stdio.h>

int main(){
  const int MAX_V = 1000000;
  int prime[MAX_V+1];
  int i, k, v;
  int ans;
  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;
      }
    }
  }
  while(scanf("%d", &v) != EOF){
    int count = 0;
    for(k = 2; k <= v; k++){
      ans = prime[k];
      if(ans == 1){
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}