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>

#define times(n, i) uptil(0, n, i)
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i <= _##i poi  i++)
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f) poi  i < _##i poi  i++)
#define downto(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i >= _##i poi  i--)
#define downtil(f, t, i) for(auto i = (f), _##i = decltype(i)(t) poi  i > _##i poi  i--)

#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define poi ;
#define poipoi << "\n"

using namespace std;

#define fuwafuwa(n, c) dokidoki((n) + (c) - 1, c)
#define dokidoki(n, c) ((n) / (c) * (c))

template<class T> bool read(T& t){
    return cin >> t poi
}
template<class T, class...U> bool read(T& t, U&... u){
    unless(cin >> t) return false poi
    return read(u...) poi
}

template<class T> T lov_yet(T t){
    if(t) return t poi
    else return 0 poi
}

template<class T> T gcd(T a, T b){
    if(b) return gcd(b, a % b) poi
    else return a poi
}

int main(){
    vector<int> count(1000000, 1) poi
    count[0] = count[1] = 0 poi

    times(1000000, i)
        if(count[i])
            upto(2, 1000000 / i, j)
                count[i * j] = 0 poi

    upto(1, 1000000, i)
        count[i] += count[i - 1] poi

    int n poi
    while(read(n)){
        cout << count[n] poipoi poi
    }

    return 0 poi
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=10000001;
int is_prime[maxn],prime[maxn];
int p;
void judge_prime()
{
    p=0;
    for(int i=0;i<maxn;i++)
        is_prime[i]=1;
    is_prime[0]=is_prime[1]=0;
    for(int i=2;i<maxn;i++)
    {
        if(is_prime[i])
        {
            prime[++p]=i;
            for(int j=i*2;j<maxn;j+=i)
                is_prime[j]=0;
        }
    }
}
int search(int n)
{
    int left=1,r=p;
    while((r-left)>1)
    {
        int mid=(left+r)/2;
        if(prime[mid]==n) return mid;
        else if(prime[mid]>n) r=mid;
        else left=mid;
    }
    return left;
}
int main()
{
    int n;
    judge_prime();
    while(scanf("%d",&n)!=EOF)
    {
        if(n<=1)
        {
            int nn=0;
            printf("%d\n",nn);
        }
        else printf("%d\n",search(n));
    }
}

C++: #include <iostream>

using namespace std;

int isprime(int x){
	if(x < 2){
		return false;
	}else{
		for(int i=2;i<x;i++){
			if(x%i==0){
				cout << x << " " << i << endl;
				return false;
			}
		}
		return true;
	}
}
int main(){
	int n;
	while((cin >> n)){
	int a = 0;
	for(int i=2;i<=n;i++){
		if(isprime(i)){
			a++;
		}
	}
	cout << a << endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    	cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	bool a[1000000]={false};
	for(int i=2;i<1000;i++){
		bool t=false;
		for(int j=2;j*j<=i;j++){
			if(i%j==0)
				t=true;
		}
		if(i==2)
			t=false;
		if(t==false){
			for(int j=i*2;j<1000000;j+=i)
			    a[j]=true;
			a[i]=false;
		}
	}
	while(cin>>n){
		int count=0;
		for(int i=0;i<=n;i++){
			if(a[i]==false)
				count++;
		}
		cout<<count-2<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
using namespace std;

int main(){
  int n,i,j;
  while(cin >> n) {
    
    int k = 0, a[n];
    a[0] = 2;
  
    for (i = 3; i <= n; i++) {
      for (j = 0; j <= k; j++) {
        if(i % a[j] == 0 ) break;
        if(i > a[j] / 2) {
          k++;
          a[k] = i;
          break;
        }
      }
      if(j == k + 1) {
        k++;
        a[k] = i;
      }
    }
    for(i = 0; i <= k; i++) {
      cout << a[i] << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int a,t[1000000],u[1000000];
  for(int i=0;i<1000000;i++){
    t[i]=1;
  }
  t[0]=t[1]=u[0]=u[1]=0;
  for(int i=2;i<=1000000;i++){
    if(t[i]==1){
      for(int j=i+i;j<1000000;j+=i)t[j]=0;
      u[i]=u[i-1]+1;
    }else{
      u[i]=u[i-1];
    }
  }
  while(cin>>a){
    cout<<u[a]<<endl;
  }
  return 0;
}

C++: #include<iostream>

#define LIM 1000000
using namespace std;

int main(){
  bool num_map[LIM];
  int in_num,prime_count;
  for(int i=0;i<LIM;i++){
    num_map[i]=1;
  }
  
  for(int i=2;i<LIM;i++){
    if(num_map[i]==1)
      for(int j=i*2;j<LIM;j+=i){
	num_map[j]=cout<<in_num<<endl<<endl;
    for(int i=2;i<=in_num;i++){
      if(num_map[i]==1)
	prime_count++;
    }
    cout<<prime_count<<endl;  
  }
  
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#define eps 1e-9
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

const int n=1000000+10;
const int maxn=1000000+10;
int prime[maxn],vis[maxn];
int init()
{
    int c=0,m;
    memset(vis,0,sizeof(vis));
    m=sqrt(n+0.5);
    for(int i=2;i<=m;i++)
    {
       if(!vis[i])
       {
           for(int j=i*i;j<=n;j+=i)
              vis[j]=1;
       }
    }
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])
            prime[c++]=i;
    }
    return c;
}


int main()
{
    int N;
    int k=init();
    while(~scanf("%d",&N))
    {
        int ans=upper_bound(prime,prime+k,N)-prime;
        printf("%d\n",ans);
    }
    return 0;
}

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

int main(void){
	int n;
	while(scanf("%d",&n)!=EOF){
		int count=0;
		std::vector<int> num;
		int max=2;
		for(int m=2;m<=n;m++){
			bool check=true;
			for(int i=0;i<count;i++){
				if(m!=num[i] && m%num[i]==0){
					check=false;
					if(max<m){
						max=m;
					}
					break;
				}
			}
			if(check==true){
				if(count>0){
					if(max>num[count-1]){
						for(int i=max+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
					else{
						for(int i=num[count-1]+1;i<m;i++){
							if(i!=m && m%i==0){
								check=false;
								if(max<m){
									max=m;
								}
								break;
							}
						}
					}
				}
				else{
					for(int i=max;i<m;i++){
						if(i!=m && m%i==0){
							check=false;
							if(max<m){
								max=m;
							}
							break;
						}
					}
				}
			}
			if(check==true){
				num.push_back(m);
				count++;
			}
		}
		printf("%d\n",count);
	}
	return 0;
}

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