Go: package main

import (
	"fmt"
	"math"
)

func main() {
	var resultArr [31]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 <cstdio>
#include <cstdlib>
#include <iostream>
#include <math.h>

using namespace std; 

int list[1000000]={2, 3, 5, 7, 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, 127, 131, 137, 139, 149, 151, 157, 163,
 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251,
 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,
 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557,
 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757,
 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863,
 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983,
 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069};

long int a,b,loop,hasil,input,mid;
long int lo;
long int hi;

 bool Prima(unsigned long n) 
{
    for (unsigned short i = 0; list[i]*list[i] <= n; i++) 
	{
        if (n % list[i] == 0) 
		{
            return false;
        }
    }
 
    return true;
}

int main()
{
	lo=1087;
	a=180;
	while(lo<=1000000)
	{
		if(Prima(lo))
		{
			list[a]=lo;
			a++;
		}
		lo+=2;
	}
	while(scanf("%ld",&input)!= EOF)
	{
		
	lo=0;
	hi=78498;
	/*while(lo<=hi)
        {
            mid=(lo+hi)/2;
            if (list[mid]<input)
            {
                lo=mid+1; 
            } 
            else if(list[mid]>input)
            {
                hi=mid-1; 
            }
            else 
            {
                break; 
            } 
        }*/
	while(input>=list[lo])
	{
		lo++;
	}
	printf("%d\n",lo);
	}
	return 0; 
}

C++: #include<stdio.h>



int main(){
	int n,i,j;
	bool c[100000];
	int data[100000];
	int count;
	int premaxin=1;


	for(i=0;i<100000;i++){
		c[i]=1;
		data[i]=0;
	}
	c[0]=c[1]=0;

	while((scanf("%d",&n)!=EOF)&&(n!=0)){

		if(premaxin<n){
			for(i=0;i<=n;i++){
				if(c[i]==1){
					if(premaxin>i){
						j=premaxin;
					}else{
						j=i+1;
					}
					for(;j<=n;j++){
						if(j%i==0){
							c[j]=0;
						}
					}
				}
			}

			count=data[premaxin];
			for(i=premaxin+1;i<=n;i++){

				if(c[i]==1){
					count++;
				}
				data[i]=count;
			}
		}

		printf("%d",data[n]);
	}
	return 0;
}

C++: #pragma  warning (disable:4996)
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
    memset(vis, 0, sizeof(vis));
    memset(prime, 0, sizeof(prime));
    prime[0] = prime[1] = 0;
     
    for (int i = 2; i*i <=MAX; i++){
        if (!vis[i]){
            prime[i] = 1;
            for (int j = i+i; j <=MAX; j += i){
                vis[j] = 1;
                prime[j] = 0;
            }
        }
    }
    /*int sum = 0;
    for (int i = 2; i <= MAX; i++){
        if (prime[i]){
            sum++;
        }
        amount[i] = sum;
    }*/
    int n;
     
    while (cin >> n){
        int sum = 0;
        for (int i = 2; i <= n; i++){
            if (prime[i]){
                sum++;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int prime[N], cnt;bool st[N];
void init() {
    st[0] = st[1] = true;
    for(int i = 2; i < N; i++) {
        if(!st[i])  prime[cnt++] = i;
        for(int j = 0; j < cnt && i * prime[j] < N; j++) {
            st[i * prime[j]] = true;
            if(i % prime[j] == 0)   break;
        }
    }
}
int main() {
    init();
    int n, sum;
    while(cin >> n) {
        sum = 0;
        for(int i = 2; i <= n; i++)
            if(!st[i])
                sum++;
        cout << sum << endl;
    }
}

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

bool IsPrime(int m){
    if(m==1){
        return(1);
    }else if(m==2){
        return(1);
    }else if(m%2==0){
        return(0);
    }else{
        for(int i=3;i*i<=m;i+=2){
            if(m%i==0)return(0);
        }
        return(1);
    }
}
int main(){
    int n;
    int r[30];
    for(int i=0;i<30;i++){
        r[i]=0;
    }
    int j=0;
    while(n!=0){
        cin>>n;
        for(int i=1;i<=n;i++){
            if(IsPrime(i))r[j]++;
        }
        cout<<r[j]<<endl;
        j++;
    }
    return(0);
}

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


using namespace std;



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

int main() {

	int num;
	while (cin >> num) {
		int count = 0;
		for (int i = 2; i <= num; i++) {
			if (isPrime(i))count++;
		}
		cout << count << endl;
	}


	
	//std::system("pause");
	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<cstdio>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
using namespace std;

#define ull unsigned long long
ull power(ull b,ull e,ull p){
	ull ret = 1;
	while(e>0){
		if((e&1)!=0){
			ret = (ret*b)%p;
		}
		b = (b*b)%p;
		e>>=1;
	}
	return ret%p;
}

bool fermat(ull p){
	if(p!=2 && p%2==0)return false;
	if(p!=3 && p%3==0)return false;
	if(p!=5 && p%5==0)return false;
	if(p!=7 && p%7==0)return false;
	for(int x=0;x<100;++x){
		ull a = rand()%(p-1)+1;
		if(power(a,p-1,p)!=1)return false;
	}	
	return true;
}

int main(){
	int n;
	while(scanf("%d",&n)==1){
		int tot = 0;
		for(int x=2;x<=n;++x){
			if(fermat(x))++tot;
		}
		cout<<tot<<endl;
	}
	return 0;
}

C++: #include<bits//stdc++.h>
using namespace std;
int main(){
	int a[1000000];
	a[0]=2;
	int z=1;
	for(int i=2;i<100000;){
		for(int j=0;j<z;j++){
			if(i%a[j]==0)goto stop;
		}
		a[z]=i;
		z++;
		stop:;
		if(i==2) i++;
		else i+=2;
	}
	int b;
	while(cin>>b){
		int c=0;
		for(int i=0;i<z;i++){
			if(a[i]>b)break;
			else c++;
		}
		cout<<c<<endl;
	}
}

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

bool isPrime(int num) {
    if(num < 2) return(false);
    for(int r = 2; r * r <= num; r++) {
        if(num % r == 0) return(false);
    }
    return(true);
}

int main(void) {
    int num;
   
    while(cin >> num) {
        int prime[num + 1];
        memset(prime, -1, sizeof(prime));
        prime[0] = prime[1] = 0;
        int sum = 1;
        
        for(int r = 3; r <= num; r += 2) {
            if(prime[r] != -1) continue;
            if(isPrime(r)) {
                prime[r] = 1;
                sum++;
                for(int c = 2 * r; c <= num; c += r) prime[c] = 0;
            }
        }
        
        cout << sum << endl;
    }
}