Go: package main

import (
        "fmt"
)

const MAX int = 1000000
var primes [MAX]int

func main() {
        Init()
        var n, cnt int
        for {
                _, err := fmt.Scanf("%d", &n)
                if err != nil {
                        break
                }
                cnt = 0
                for i := 2; i <= n; i++ {
                        cnt += primes[i]
                }
                fmt.Printf("%d\n", cnt)
        }
}

func Init() {
        for i := 0; i < MAX; i++ {
                primes[i] = i
        }

        Soe()

        for i := 0; i < MAX; i++ {
                primes[i] %= 2
        }
        primes[1] = 0
        primes[2] = 1
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := 2; j < MAX/i; j++ {
                                if i * j < MAX {
                                        primes[i*j] = 0
                                }
                        }
                }
        }
}

C++: #include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cstdio>

using namespace std;

void Eratosthenes(vector<int> &S_List, vector<int> &P_List){
	while(1){
		vector<int>::iterator it = S_List.begin();
		P_List.push_back(*it);  //先頭を素数リストへ追加
		int num = *it;
		while (it != S_List.end()){
			if ((*it % num) == 0){
				it = S_List.erase(it); //探索リストから倍数を除外
			}
			else{
				++it;
			}
		}
		vector<int>::iterator P_it = max_element(P_List.begin(), P_List.end());
		double p_max_sqr = sqrt(*P_it);
		vector<int>::iterator S_it = max_element(S_List.begin(), S_List.end());
		if (S_List.empty() == true){
			return;
		}
		if (*S_it < p_max_sqr){
			return;
		}
		/*else{
			Eratosthenes(S_List, P_List);
		}*/
	}
}


void output(vector<int> ex){
	/*vector<int>::iterator it = ex.begin();
	while(it != ex.end()){
		cout << *it << endl;
		++it;
	}*/
	cout << ex.size() << endl;
}

int main(void){
	
	int num;
	while (cin >> num){
		/*clock_t start = clock(); */
		vector<int> S_List, P_List;
		if (num < 4){
			for (int i=2; i<num; ++i){
				S_List.push_back(i);
			}
		}
		else{
			int c = 1;
			S_List.push_back(2);
			S_List.push_back(3);
			while((6*c+1) <= num){
				S_List.push_back(6*c-1);
				S_List.push_back(6*c+1);
				++c;
			}
			if (6*c-1 <= num){
				S_List.push_back(6*c-1);
				}
		}
		Eratosthenes(S_List, P_List);
		output(P_List);
		/*clock_t end = clock();
		printf("%.4f[sec]\n",(double)(end-start)/CLOCKS_PER_SEC);*/
	}
	return 0;
}

C++: #include <iostream>
const int MAX_V = 1000000; // 100????????§?´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°???0????´???°??§?????? 
int pcount[MAX_V+1];
int main() {
    int i, k,a,sum=0;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1; // 2??\????´???°??¨??????
    } 
    for(i = 2; i*i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°2?????\????????°?´???°??§?????? 
            }
            
        } 
        
    }
    pcount[0]=0;
    pcount[1]=0;
    for(i=2;i<MAX_V;i++){
        if(prime[i]){
            sum++;
        }
        pcount[i]=sum;
    }
    for(i=0;i<30;i++){
        scanf("%d",&a);
        printf("%d\n",pcount[a]);
    } 

    return 0; 
    
}

C++: #include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define MAX_NUM 999999
vector<LL> vecsosuu;

void makesosuu(void){
	FOR(i, 2 ,MAX_NUM){
		bool flag = true;
		if(i == 2){
			vecsosuu.pb(i);
		}else if(i % 2 != 0){
			int j = 3;
			while(j <= sqrt(i)){
				if(i % j == 0){
					flag = false;
				}
				j += 2;
			}
			if(flag){
				vecsosuu.pb(i);
			}
		}
	}
}

LL sosuu(LL n){
	LL i = 0;
	while(n >= vecsosuu[i]) ++i;

	return i;
}

int main(){
	LL n;
	makesosuu();
	while(cin >> n){
		cout << sosuu(n) << endl;	
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+100;
const int maxn=90000+5;
int prime[maxn];
bool p[MAXN];
int cnt;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt++]=i;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	cnt=0;
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	int n;
	while(~scanf("%d",&n)){
		int k=lower_bound(prime,prime+cnt,n)-prime+1;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool p[1000000]={true,true};
int main(){
  for(int i=2; i<1000; i++)
    if(!p[i])
      for(int j=i*i; j<1000000; j+=i)
	p[j] = true;
  int n;
  while(cin >>n){
    int solve = 0;
    for(int i=0; i<=n; i++)
      if(!p[i])
	solve++;
    cout <<solve<<endl;
  }
  return 0;
}

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

int main(){

int i,j,n,count;

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

count=2;

if(n<5){
	count=n-1;
}else{
	for(i=5;i<n+1;i+=2){
		for(j=2;j<(int)sqrt(i)+1;j++)

			if(i%j==0){
				break;
			}else if(j==(int)sqrt(i))
				count+=1;
	}
}

printf("%d\n",count);

}
return 0;		
}

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

using namespace std;

const int MAX_N = 1000000;
bool prime[MAX_N];

void eratos() {
    for (int i = 0; i < MAX_N; ++i) prime[i] = true;
	prime[0] = false;
	prime[1] = false;
	for (int i = 2; i < sqrt(MAX_N); ++i) {
		if (prime[i]) {
			for (int j = 0; i * (j + 2) < MAX_N; ++j) {
				prime[i * (j + 2)] = false;
			}
		}
	}
}

int main() {
	eratos();
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 2; i <= n; ++i) {
			if (prime[i]) ans++;
		}
		cout << ans << endl;
	}
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m;
int prime(int n)
{
    for(int i=2;i*i<=n;i++)
        if(n%i==0) return 0;
    return 1;
}
int main()
{
   while(cin>>n)
   {
       int s=0;
       for(int i=2;i<=n;i++)
        if(prime(i)) s++;
       cout<<s<<endl;
   }
    return 0;
}

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

typedef long long ll;
 
ll mod_pow(ll x, ll n, ll mod){
  ll res = 1;
  while(n > 0){
    if(n & 1) res = res * x % mod;
    x = x*x % mod;
    n >>= 1;
  }
  return res;
}

ll mod_mul(ll x, ll n, ll mod){
  x %= mod;
  n %= mod;
  return x*n % mod;
}

bool millrr_rabin(ll n){
  if(n == 2) return true;
  if((n & 1) == 0 || n <= 1) return false;
  int a[] = {2, 3, 5, 7, 11, 13, 17, -1}, r;
  ll s = 0, d, x;
  d = n - 1;
  while((d & 1) == 0){
    s++;
    d = d >> 1;
  }
  
  for(int i = 0 ; a[i] != -1 && a[i] < n ; i++){
    if((x = mod_pow(a[i], d, n)) != 1){
      for(r = 0 ; r < s ; r++){
	if(x == n-1) break;
	x = mod_mul(x, x, n);
      }
      if(r == s) return false;
    }
  }
  return true;
}

int main(){
  
  int n;
  while(cin >> n){
    int ans = 0;
    for(int i = 2 ; i <= n ; i++){
      if(millrr_rabin(i)) ans++;
    }
    cout << ans << endl;
  }
  
  
  return 0;
}