Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N;

constexpr ll max_n = 1000006;
bool prime[max_n];

void solve(){
    int cnt=0;
    for(int i=2;i<=N;i++) if(prime[i]) cnt++;
    cout << cnt << endl;
}

int main(){
    rep(i,max_n) prime[i]=true;
    for(int i=2;i*i<max_n;i++){
        if(!prime[i]) continue;
        for(int j=i*i;j<max_n;j+=i) prime[j] = false;
    }

    while(cin>>N){
        solve();
    }
}

C++: #include<iostream>
#include<math.h>
using namespace std;
int tim(int n)
{
	int i,s=0;
	int *a;
	a=new int [n+1];
	for(i=1;i<=n;i++)
	a[i]=1;
	for(i=2;i*i<=n;i++)
	{
		if(a[i]!=0)
		for(int j=i*i;j<=n;j=j+i)
		a[j]=0;
	}
	for(i=2;i<=n;i++)
	if(a[i]==1)
	{
	s=s+1;
   } 
	return s;
}
int main()
{
	int n,i=1,a[100000];
	do
	{
		int k;
		cin>>a[i];
		if(a[i]<2)
		k=0;
		else
		k=tim(a[i]);
		cout<<k;
		cout<<endl;
	}
	while(1);
}

C++: #include <stdio.h>
  
int main(){
    int e[30];
  
    int k = 0;
    while( scanf( "%d",&e[k] ) != EOF )k++;
  
    for( int i = 0;i < k;i++ ){
        int n = 1;
        int k = 0;
        while( true ){
            if( e[k] > n ){
                k++;
                n *= 10;
            } else {
                break;
            }
        }
        printf( "%d\n",k );
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int count=0;
		for(int i=5;i<=n;i+=2){
			int j=3;
			while(true){
				if(i%j==0)
					break;
				if(j>(int)sqrt((double)i)){
					count++;
					break;
				}
				j++;
			}
		}
		cout<<count+1<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int P[1000000] = {};
	int c = 0, j, k;
	for (k = 2; k < 1000000; ++k){
		if (P[k] == 0){
			++c;
			for (j = 2; j * k < 1000000; ++j)
				P[j * k] = -1;
		}
		P[k] = c;				
	}
	while (cin >> k)
		cout << P[k] << "\n";
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int count1,count2;
  while(1){
    cin >>n;
    count2=0;
    for(int i=n;i>1;i--){
      count1=0;
      for(int j=2;j<i;j++){
	if(i%j==0){
	  count1++;
	  break;}
      }
      if(count1==0)count2++;}
      cout <<count2<<endl;
    }
  return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
int main()
{
    int n;
    set<int> prime;
    while(cin >> n)
    {
        for(int i = 2; i <= n; i++)
        {
            bool is_prime = true;
            int tmp = 2;
            for(auto num : prime)
            {
                if(num >= i) break;
                if(i % num == 0)
                {
                    is_prime = false;
                    break;
                }
                tmp = num;
            }
            for(int j = tmp; is_prime && j <= i / 2; j++)
            {
                if(i % j == 0)
                {
                    is_prime = false;
                    break;
                }
            }
            if(is_prime) 
            {
                prime.insert(i);
            }
        }
        int cnt = prime.size();
        for(auto it = prime.rbegin(); it != prime.rend(); it++)
        {
            cerr << *it << ' ';
            if(n < *it) cnt--;
            else break;
        }
        cout << cnt << endl;
    }
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main() {
  int prime_flag[1000000];
  FOR(i, 2, 1000000) prime_flag[i] = 1;
  int t = 2;
  while(t < 1000000/2) {
    if(prime_flag[t]) {
      int k = 2;
      while(t * k < 1000000) {
	prime_flag[t*k] = 0;
	k++;
      }
    }
    t++;
  }
  int n;
  while(scanf("%d", &n) != EOF) {
    t = 0;
    REP(i, n+1) t += prime_flag[i];
    printf("%d\n", t);
  }
  
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    char x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

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

bool isprime(int n){
    if(n==0 || n==1){
        return false;
    }
    if(n==2){
        return true;
    }
    for(int i=2;i<n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

int solve(int x){
    int m = 0;
    for(int i=0;i<=x;i++){
        if(isprime(i)){
            m++;
        }
    }
    return m;
}
int main(){
    int n;
    while((cin>>n)){
        cout << solve(n) << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    int x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        c++;
        x[a]=c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}