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 <cmath>
#include <climits>

using namespace std;
//?数表
const unsigned long long maxn=100000;//定?最大数
const unsigned long long mmax=maxn/2+1;//数?的大小
bool nprilist[mmax];//注意false才是?数
void fsetupprime()//?数表建立函数
{
    //const unsigned long long half=mmax/2+1;//定?二分??界限
    unsigned long long prei=1;//用来?存上一个起始点
    for(unsigned long long i=1;i<mmax;++i)//二分??前半段
    {
        cout<<0<<endl;
        if(!nprilist[i])
        {
            unsigned long long j=2*prei*prei+2*prei;
            while((2*j+1)%(2*i+1))
                ++j;
            for(;j<=mmax;j+=2*i+1)//j=((2i+1)^2-1)/2=2i^2+2i，i就是?里的prei，然后本来j???再加一个1的，但?了方便第一次i=3的循??一，故??里?界重?，若???要求?高，?在?里加1以?小????度
                {nprilist[j]=1;cout<<"1"<<endl;}
            prei=i;
        }
    }
    /*for(unsigned long long i=half;i<mmax;++i)//二分??后半段
    {
        cout<<3<<endl;
        for(unsigned long long j=1;j<half;++j)
        {
            cout<<4<<endl;
            if(nprilist[j])
                continue;
            else if(!((2*i+1LL)%(2*j+1LL)))
            {
                nprilist[i]=1;
                break;
            }
        }
    }*/
    return;
}
bool fis_prime(const unsigned long long &a)//?数判断接口函数
{
    if(a>2)
    {
        if(!(a&1))
            return 0;
        return !nprilist[(a-1)/2];
    }
    if(a==2)
        return 1;
    if(a==0||a==1)
        return 0;
}
//?数表?束


int main()
{
    fsetupprime();
    long long a=0;
    while(cin>>a)
    {
        int sum=0;
        if(a==0&&1)
            cout<<0<<endl;
        if(a==2)
            cout<<1<<endl;
        else
        {
            for(long long i=3;i<=a;i+=2)
                if(fis_prime(i))
                    ++sum;
            cout<<++sum<<endl;
        }
    }
    return 0;
}

C++: #include<iostream>
int m,n,p;void r(){p++;if(m<2)p--;else{for(int i=3;i*i<=m;i+=2)if(m%i==0){p--;break;}}}int main(){for(;!(std::cin>>n).eof();){if(n<3)p=!(n-2);else for(m=3,p=1;m<=n;m+=2)r();printf("%d\n",p);}}

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

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
while(cin >> n,!cin.eof()){
vector<int> prime;
prime.push_back(2);//ôðÈ­½ß2ÍÅÉüêÄ¨­
bool flag;
for(int x=3;x<=n;x+=2){
flag=true;
for(int y=0;prime[y]*prime[y]<=x;y++){
if(!(x%prime[y])){
flag=!flag;
break;
}
}
if(flag)prime.push_back(x);
}
cout << prime.size() << endl;
prime.clear();
}
return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define ll long long int

using namespace std;

int cnt(int n)
{
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}

int main()
{
    int n,i,j,c=0,x;

    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        {
            if(i>2)
            {
                x=cnt(i);
                if(x==1)
                    c++;
            }
            else if(i==2)
                c++;
        }
        cout<<c<<endl;
        c=0;
    }







    return 0;
}

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

#define MAX 100000

using namespace std;

bool prime[MAX+1];
int T[MAX];

void eratos(int n) {
  for(int i = 0; i < n; i++) prime[i] = false;
  for(int i = 3; i <=n; i+=2)prime[i] = true;
  prime[2] = true;
  for(int i = 3, limit = (int)sqrt(n); i <= limit; i += 2) {
    if(!prime[i]) continue;
    for(int j = i*i, k = i*2; j <= n; j += k) prime[j] = false;
  }
}

void init() {
  eratos(MAX);

  for(int i = 0; i < MAX; i++) {
    T[i] = T[i-1];
    if(prime[i]) T[i]++;
  }
}

main() {
  init();
  int n;
  
  while(cin >> n) cout << T[n] << endl;
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main(void){
	int i,j,k,n,a;
	while(cin >> n){
		a=1;
	if(n==1){
		cout << "0\n";
	}
	else{
		for(i=3;i<=n;i+=2){
			k=0;
			for(j=3;j<=sqrt(i);j+=2){
				if(i%j==0){
					k=1;
					break;
				}
			}
	
			if(k==0) a++;
		}
	}

	printf("%d\n",a);
	}
	return 0;
}

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

int main(void){
    int num;
    while(cin>>num){
        int ans=0;
        for(int i=2;i<=num;i++){
            int check=0;
            for(int j=2;j*j<=i;j++){
                if(i%j==0){check++;break;}
            }
            if(check==0)ans++;
        }
        cout<<ans<<endl;
    }
}

C++: #include <iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<stack>
#include <string>
#include<fstream>
#include<ctime>
#include<queue>

using namespace std;
#define LL long long
#define mxn 100010
#define mxe 1000010
#define eps 1e-4
#define inf 0x7fffffff

#include<iostream>
#include<cstdio>
#define INF 999999999;
#include<iostream>
using namespace std;

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#define MAX 1000000
using namespace std;
int amount[MAX];
int vis[MAX];
int prime[MAX];
int main(){
	memset(vis, 0, sizeof(vis));
	memset(prime, 0, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i*i<= MAX; i++){
		if (!vis[i]){
			prime[i] = 1;
			for (int j = i + i; j <= MAX; j += i){
				vis[j] = 1;
				prime[j] = 0;
			}
		}
	}
	int sum = 0;
	for (int i = 0; i <= MAX; i++){
		if (prime[i]){
			sum++;
		}
		amount[i] = sum;
	}
	int n;
	while (cin >> n){
		cout << amount[n] << endl;
	}
	return 0;
}

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

#define rep(i, n) for(int i = 2; i <= n; i ++)

using namespace std;

int main(void){
	for(int n, count = 0; cin >> n; cout << count << endl, count = 0){
		vector<bool> numberList(n + 1);

		rep(i, n) numberList[i] = true;

		rep(i, n) for(int j = i; i * j <= n; j ++) numberList[i * j] = !(numberList[i * j]);
		
		rep(i, n) if(numberList[i]) count ++;
	}

	return 0;
}