Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

C++: #include<bits/stdc++.h>
#include<cstdio>

using namespace std;

int pri[1000000];

int main()
{

    pri[0]=1;
    pri[1]=1;

    for(int i=4;i<1000000;i+=2)
    {
        pri[i]=1;
    }

    for(int i=2;i*i<1000000;i++)
    {
        for(int j=2;j*i<1000000;j++)
        {
            pri[i*j]=1;
        }
    }
    int n,c;
    while(scanf("%d",&n))
    {
        c=0;
        for(int i=2;i<=n;i++)
        {
            if(pri[i]==0)
            {
                c++;
            }
        }
       printf("%d\n",c);

    }

    return 0;
}