Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

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;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;

int main(int argc, char const* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    vector<int> nl;
    int mx = 0;
    do{
        int n;
        cin >> n;
        if (!cin.eof()){
            nl.push_back(n);
            mx = max(mx, n);
        }else{
            break;
        }
    }while(1);


    double r = sqrt(mx);

    list<int> sl;
    vector<int> primes;

    for (int i = 2; i <= mx; i++) {
        sl.push_back(i);
    }

    while (sl.front() <= r) {
        int p = sl.front();
        primes.push_back(p);
        sl.pop_front();

        auto i = sl.begin();
        while(i != sl.end()){
            if(*i % p == 0){
                i = sl.erase(i);
            }
            else {
                i++;
            }
        }
    }

    for (auto&& i : sl) {
        primes.push_back(i);
    }

    for (auto&& n : nl) {
        auto p = upper_bound(primes.begin(), primes.end(), n);
        cout << p - primes.begin() << endl;
    }

    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
	int n,k,kk;
	while(cin>>n){
		kk=0;
		for(int j=3;j<=n;j+=2){
			k=0;
			for(int i=3;i<=sqrt(j);i+=2){
				if(j%i==0)k++;
		        }
		     if(k==1)kk++;
		   }
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<"1"<<endl;
		else cout<<kk+1<<endl;
	   }
	return 0;
	}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];void k();using namespace std;main(){int n;p[0]=2;m[1]=0;m[2]=1;k();while(cin>>n){cout<<m[n]<<endl;}}void k(){int i,j,e=1;for(i=3;i<N+1;i++){for(j=0;p[j]*p[j]<=i;j++){if(i%p[j]==0){goto tag;}}p[e]=i;e++;tag:m[i]=e;}}