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 <iostream>
using namespace std;

#define long long long
const long N = 10000000;
bool np[N];
long p[N], pp=0;

void eratos() {
    np[0]=np[1]=true;
    for (long i=2; i*i<N; i++) if (!np[i])
        for (long j=i*i; j<N; j+=i) np[j]=true;
    for (int i=2; i<N; i++)
    if (!np[i]) p[++pp]=i;
}
main()
{
	eratos();
	long n,d=0;
do
{
d=0;
	cin>>n;
	for(long i=1;i<n;i++)
	if(p[i]>n)
	{cout<<i-1<<endl; 
	break;}
}while(1);
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string.h>
using namespace std;
const int N=11111;
vector<int> prime;
int sieve(long long 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(){
long long num;
int a;
for(int i=0;i<30;++i){
    scanf("%lld",&num);
    a=sieve(num);
    printf("%d\n",a);
}
return 0;
}

C++: int main(){
	int i , j , n , pn , cn=0;
	
	while(cin>>n){
		pn=1;
		for(i=3 ; i<=n ; i++){
			for (j=2 ; j<i ; j++){
				if (i%j==0) goto skip;
			}
			pn++;
			skip:;
		}
		if(n==0 || n==1 ) {
			cout << 0 << endl;
		} else {
			cout << pn << endl;
		}
		cn++;
		if(cn>=30) break;
	}
	return 0;
}

C++: import math

def isPrime(n):
	if n==1: return False
	if n==2: return True
	for i in range(2,int(math.sqrt(n))+2):
		if n%i==0: return False
	return True

while True:
	a = input()
	if a=='EOF': break
	sum = 0
	for i in range(1,a+1):
		if isPrime(i)==True:
			sum+=1
	print sum

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/

bool prime[1000000];
int ans[1000000];

void is_prime(){
  rep(i,1000000)prime[i]=true;
  prime[0]=prime[1]=false;
  REP(i,2,1000000){
    if(prime[i]==true){
      for(int j=i+i;j<1000000;j+=i)prime[j]=false;
    }
  }
  if(debug)rep(i,1000)if(prime[i])cout<<i<<endl;
}

void calc(){
  ans[0]=0;
  REP(i,1,1000000){
    ans[i]=ans[i-1]+prime[i];
  }
}

int main(){
  int n;
  is_prime();
  calc();
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

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

int main(){
	int n;
	int sosu[100000];
	int snum;
	bool judge;

	sosu[0] = 2;

	while(cin >> n){
		snum = 0;
		for(int i = 3; i <= n; i++){
			judge = true;
			for(int j = 0; sosu[j]*sosu[j] <= i; j++){
				if(i%sosu[j] == 0){
					judge = false;
					break;
				}
			}
			if(judge == true){
				snum ++;
				sosu[snum] = i;
			}
		}
		if(n == 1){
			cout << 0 << endl;
		}else{
			cout << snum + 1 << endl;
		}
	}



	return(0);
}

C++: #include<cstdio>

bool isprime[1000000];

void eratos(){
	for(int i=0;i<1000000;i++){
		isprime[i] = true;
	}
	isprime[0] = isprime[1] = false;
	for(int i=2;i<=1000;i++){
		if(isprime[i] == true){
			int j = i + i;
			while(j < 1000000){
				isprime[j] = false;
				j = j + i;
			}
		}
	}
}

int main(void){
	int n;
	eratos();
	while(scanf("%d",&n) != EOF){
		int cnt = 0;
		for(int i=0;i<=n;i++){
			if(isprime[i] == true){
				cnt++;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

#define MAX 1000000
int prime[MAX];

int main()
{
	int number,count=0;
	prime[0] = prime[1] = 0;

	for(int i=2;i<MAX;i++)
	{
		prime[i] = 1;
	}
	for(int i=2;i<1001;i++)
	{
		if(prime[i])
		{
			for(int j=2*i;j<MAX;j += i)
			{
				prime[j] = 0;
			}
		}
	}

	while(cin >> number)
	{
		count = 0;
		for(int i=2;i<=number;i++)
		{
			count += prime[i];
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    while(cin>>n){
        bool prime[1000000]={false};
        prime[1]=true;
        prime[2]=false;
        int cou=0;
        for(int i=2;i*i<=n;i++){
            if(!prime[i]){
                for(int j=2;i*j<=n;j++){
                    prime[i*j]=true;
                }
            }
        }
        for(int i=1;i<=n;i++){
            if(!prime[i])cou++;
        }
        cout<<cou<<endl;
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;


vector<int> p;
int main(void){
    p.pb(2);
    for(int i = 3; i <1000000; i += 2){
        int j;
        for(j = 0; p[j] * p[j] <= i; ++j){
            if(i % p[j] == 0) break;
        }
        if(i % p[j] > 0) p.pb(i);
    }
    int n;
    while(cin >> n){
        int l = 0, r = p.size();
        while(l + 1 != r){
            int t = (l + r)/2;
            if(p[t] <= n) l = t;
            else r = t;
        }
        int ret;
        if(n < p[r]) ret = r;
        else ret = l;
        cout << ret << endl;
    }
    return 0;
}

C++: #include <cstdio>
#define max_n 999999
#define INF 1000000
int prime[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        prime[i] = INF;
        is_prime[i]=true;
    }
    int p = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    while(scanf("%d",&n)!=EOF){
        printf("%d\n",n);
        int ans = 0;
        for(int i =0; i<max_n; i++){
            if(prime[i]>n){
                ans = i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}