Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [100]int
	var inputCount, primeCount, input int
	for {
		fmt.Scanf("%d", &input)
		for i := 0; i <= input; i++ {
			if IsPrime(i) {
				primeCount++
			}
		}
		resultArr[inputCount] = primeCount
		if inputCount == 30 {
			break
		}
		primeCount = 0
		inputCount++
	}
	for _, v := range resultArr {
		fmt.Printf("%d\n", v)
	}
}

func IsPrime(num int) bool {
	switch {
	case num == 2:
		return true
	case num < 2 || num%2 == 0:
		return false
	}
	sqrt := math.Sqrt(float64(num))
	for i := 3; i <= int(sqrt); i += 2 {
		if num%i == 0 {
			return false
		}
	}
	return true
}

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

C++: #include <stdio.h>
#include <string.h>
#define SIZE_VALUE 1000005

int main(){
    bool prime[SIZE_VALUE];
    int i,count=0,input;
    memset(prime,0,sizeof(prime));
    for(i=2;i*i<SIZE_VALUE;i++){
        if(prime[i]==0)
        for(int j=i*i;j<SIZE_VALUE;j+=i){
            prime[j]=1;
        }
    }
    while(scanf("%d",&input)==1){
        count=0;
    for(i=2;i<=input;i++){
        if(prime[i]==0)
            count++;
    }
    printf("%d\n",count);
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string.h>
using namespace std;
vector<int> prime;
int sieve(int n){
   bool arr[n+1];
   int cnt=0;
   memset(arr,true,sizeof(arr));
   for(int i=2;i<=n;++i){
    if(arr[i]){
        prime.push_back(i);
        cnt++;
    }
    for(int j=0;j<prime.size()&&i*prime[j]<n;j++){
        arr[i*prime[j]]=false;
        if(i%prime[j]==0)break;
    }
   }
   return cnt;
}

int main(){
int num;
int a;
while(true){
    scanf("%d",&num);
    if(!num) break;
    a=sieve(num);
    printf("%d\n",a);
}
return 0;
}

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

const int MAX_V = 10000;
int prime[MAX_V+1];

void init(){
    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;
            }
        }
    }   
}

int isprime(int n){
    return prime[n];
}

int main(){
    init();
    int num;
    // while(1){
    while(cin >> num){
        int count=0;
        // scanf("%d", &num);
        for(int i=2; i<=num; i++){
            if(isprime(i)==1)
                count++;
        }
    printf("%d\n", count);
    }
    return 0;
}

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

#define MAX 1000000

using namespace std;

bool prime[MAX+1];
int T[MAX];

void eratos(int n) {
  for(int i = 0; i < n; i++) prime[i] = false;
  for(int i = 3; i <=n; i+=2)prime[i] = true;
  prime[2] = true;
  for(int i = 3, limit = (int)sqrt(n); i <= limit; i += 2) {
    if(!prime[i]) continue;
    for(int j = i*i, k = i*2; j <= n; j += k) prime[j] = false;
  }
}

void init() {
  eratos(MAX);

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

int main(void) {
  init();
  int n;
  
  while(cin >> n) cout << T[n] << endl;
  return 0;
}