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()
{
    int n, j, sum = 0, flag = 0;


    while(scanf("%d", &n) == 1)
    {
        for(j = 2; j <= n; j++)
        {
            if(j % 2 == 0 && j != 2)
            {
                flag = 1;
            }
            else if(j % 3== 0 && j != 3)
            {
                flag = 1;
            }
            else if(j % 5== 0 &&  j != 5)
            {
               flag = 1;
            }
            else if(j % 7 == 0 && j != 7)
            {
               flag = 1;
            }
            if(flag == 0)
            {
                sum = sum + 1;
            }
            flag = 0;

        }
        printf("%d\n", sum);
        flag = 0;
        sum = 0;
    }
    return 0;
}

C++: #include <cstdio>
#include <vector>

using namespace std;

int main()
{
	int n;
	vector<int> prime;
	
	for (int i = 3; i < 10000000; i += 2){
		int j;
		for (j = 1; j < prime.size(); j++){
			if (i % prime[j]){
				break;
			}
		}
		if (j >= prime.size()){
			prime.push_back(i);
		}
	}
	while (scanf("%d", &n) != EOF){
		int count;
		
		for (count = 1; prime[count - 1] < n; count++);
		if (n >= 2){
			count++;
		}
		printf("%d\n", count);
	}
	
	return 0;
}

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

#define MAX 1000000

int main()
{
	int n;
	int prime[MAX];

	prime[0] = prime[1] = false;

	for (int i = 2; i < MAX; i++){
		prime[i] = true;
	}

	for (int i = 0; i < MAX; i++){
		for (int j = i * i; j < MAX; j += i){
			prime[j] = false;
		}
	}

	for (int i = 0; i < MAX; i++){
		prime[i + 1] += prime[i];
	}

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

	return (0);
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> prime_list;
  bool flag;

  prime_list.push_back(2);
  for (int i = 3; i < 50; i++) {
    for (int j = 0; j < prime_list.size(); j++) {
      if(i%prime_list[j] == 0) {
        flag = false;
        break;
      } else {
        flag = true;
      }
    }
    if (flag) {
      prime_list.push_back(i);
    }
  }

  int data, count;
  while(cin >> data) {
    for (int i = 0; i < prime_list.size() && prime_list[i] <= data; i++, count = i);
    cout << count << endl;
  }
}

C++: #include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
	int max,n[1000],c = 0,check;
	while(cin >> max){
		c = 0;
		for(int i = 2;max >= i;i++){
			check = 0;
			for(int iii = 1;c >= iii;iii++){
				if(i % n[iii] == 0){check = 1;break;}
			}
			for(int ii = 2;i > ii and check == 0;ii++){
				if(i % ii == 0){check = 1;break;}
			}
			if(check == 0){c++;n[c] = i;}

		}
		cout << c << endl;
	}



}

C++: #include <stdio.h>

#define MAX (100000)

int main(void)
{
	int prime[MAX + 1] = {1};
	int n;
	int ans;
	int i;
	
	for (int i = 0; i <= MAX; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	i = 0;
	while (i * i <= MAX){
		while (prime[++i] != 1 && i * i <= MAX);
		//printf("%d ", i);
		for (int j = 2; j * i <= MAX; j++){
			//printf("%d\n", i * j);
			prime[i * j] = 0;
		}
	}
	
	scanf("%d", &n);
	
	ans = 0;
	for (int i = 2; i <= n; i++){
		if (prime[i] == 1){
			ans++;
		}
	}
	
	printf("%d\n", ans);
	
	return (0);
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 0;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 0;
		
		for (int i = 1;i<=num;i++) {
		if(i%2==0) {
			//cout <<"2: "<<i<<endl;
			count ++;
			continue;
		}
		for (int j=3;j<(int)sqrt(i)+1;j=j+2) {
			if (i%j==0) {
				count ++;
				//cout <<"i: "<<i<<" j: "<<j<<endl;
				break;
			}
		}
	}
	cout << (num-count) <<endl;
	//cout << endl;
	}
	return 0;
}

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

vector<int> sieve_of_eratosthenes(int n) {
    vector<int> prime(n + 1, 0);
    for (int i = 2; i <= n; ++i) prime[i] = i;
    for (int i = 2; i * i <= n; ++i) {
        if (prime[i]) {
            for (int j = i * i; j <= n; j += i) prime[j] = 0;
        }
    }
    // prime.erase(remove(begin(prime), end(prime), 0), end(prime));
    return prime;
}

int main() {
    auto prime = sieve_of_eratosthenes(1e6);
    for (int n; cin >> n;) {
        int ans = 0;
        for (int i = 0; i <= n; i++) {
            if (prime[i]) ans++;
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,n;
    n=0;
    while ( cin >> a){
        for (int i=2;i<a;i++){
            if (prime(i)==0){
                n++;
            }
        }
        cout << n << endl;
    }
}


int prime(int x){
    if(x==2 || x==3 || x==5 || x==7)
        return 0;
    if(x%2==0 || x%3==0 || x%5==0)
        return 1;
    for (int i=7;i<=sqrt(x)+2;i+=30){
        if(x%i==0 || x%(i+4)==0 || x%(i+6)==0 || x%(i+12)==0 || x%(i+16)==0 || x%(i+22)==0 || x%(i+24)
            return 1;
    }
    return 0;
}

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

C++: #include <cstdio>

int Eratos[1000000];

int main()
{
	Eratos[0] = Eratos[1] = 0;
	for (int i = 2; i < 1000000; i++){
		Eratos[i] = 1;
	}
	for (int i = 2; i < 1000; i++) {
		if (Eratos[i]) {
			for (int j = 2 * i; j < 1000000; j += i) {
				Eratos[j] = 0;
			}
		}
	}
	int n,res;
	res = 1;
	for (int i = 2; i < 1000000; i++) {
		if (Eratos[i]) {
			Eratos[i] = res;
			res++;
		}
	}
	while (scanf("%d", &n) != EOF) {
		res = 0;
		while (!Eratos[n]) {
			n--;
			if (n == 0)
				break;
		}
		if (n)
			printf("%d\n", Eratos[n]);
		else
			printf("0\n");
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>

using namespace std;

const int a[] = {1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 121, 127, 131, 137, 139, 143, 149, 151, 157, 163, 167, 169, 173, 179, 181, 187, 191, 193, 197, 199, 209};

int func(int v)
{
	int b = v / 210;
	int c = -1;

	int left=0, right=48;
	do{
		int mid = (left+right)/2;
		if(a[mid] == v-b*210){
			c = mid;
			break;
		}else if(a[mid] < v-b*210)
			left = mid + 1;
		else
			right = mid - 1;
	}while(left<=right);

	return c == -1 ? -1 : b*48 + c;
}

int main(void)
{
	unsigned char* eratos = new unsigned char[28572000];
	fill(eratos, eratos+28572000, 0);
	eratos[0] = 1;

	int cnt = 4;
	int i, j, k, n;
	scanf("%d", &n);
	if(n==1) return 0;
	if(n==2) return 1;
	if(n<=4) return 2;
	if(n<=6) return 3;

	for(i=0; i*210<n; ++i){
		for(j=0; j<48; ++j){
			int v = i*210 + a[j];
			int pos;
			if(v>n)
				break;
			pos = func(v);
			if(!((eratos[pos/8]>>(pos%8))&1)){
				++cnt;
				for(k=v*2; k<=n; k+=v){
					int p = func(k);
					if(p != -1)
						eratos[p/8] |= 1<<(p%8); 
				}
			}
		}
	}

	printf("%d\n", cnt);
	delete[] eratos;

	return 0;
}