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 <vector>

using namespace std;

int main()
{
    vector<int> ans(0);
    bool p[999999]; for (int i=0; i<999999; i++) p[i]=true;
    p[1]=false;
    int sum=0, n;
    for (int i=2; i<998; i++)
    {
        for (int j=i+i; j<998; j+=i) p[j]=false;
    }
    while (cin>>n)
    {
        for (int i=1; i<=n; i++) if (p[i]) sum++;
        ans.push_back(sum);
        sum=0;
    }
    for (int i=0; i<ans.size(); i++) cout<<ans[i]<<'\n';
    return 0;
}

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

int main() {
int b[1000000];
for (int k=0;k<1000001;k++){
	b[k]=0;
}
b[2]=1;
b[3]=1;
b[4]=0;
b[5]=1;
b[6]=0;
b[7]=1;

for (int p=11;p<1000001;p+=2){
int i,a=0 ;
	i=3;
	while(i<=sqrt(p)){
		if(p%i==0){
			break;
	}i=i+2;
	}
	if (i>sqrt(p)){
		a=1;
	}
	b[p]=a;
}
int c[1000000];
for (int l=0;l<1000001;l++){
	c[l+1]=c[l]+b[l+1];
}
int r;
while(cin>>r){
	cout<<c[r]<<endl;
}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
	bool num[1000000] = {0};
	for(int i=2; i<1000; i++){
		if(!num[i]){
			for(int j=i*i; j<1000000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

C++: #include <iostream>
#include <cmath>
#define	NUM		1000000
using namespace std;

bool sosuu[NUM+1] = {false};
int t = 0;
int out[30];

void Prime(int a)
{
	int count = 0;
	int x;
	x = floor(sqrt(a));
	for(int i = 2; i < x+1; i++){
		if(sosuu[i] == true){
			continue;
		}
		for(int j = 2*i; j < a+1; j = j+i){
			sosuu[j] = true;
		}
	}
	for(int i = 2; i < a+1; i++){
		if(sosuu[i] == false){
			count++;
		}
	}
	out[t] = count;
}

int main()
{
	int n;
	while(cin >> n){
		Prime(n);
		t++;
	}
	for(int i = 0; i < t; i++){
		cout << out[i] << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	int a,n,i,j;
	for(int l=0;l<2;l++){
	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<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <math.h>

bool is_prime(std::vector<int> &primes, int n){
	bool ret = true;
	int max_i = sqrt(n);

	for(int i = 0; i < primes.size(); i++){
		if(primes[i] > max_i){break;}
		if(n % primes[i] == 0){
			ret = false;
			break;
		}
	}
	return ret;
}

int main(int argc, char **argv){
	int n = 0;
	std::vector<int> primes;

	primes.push_back(2);

	while(std::cin >> n){
		int num_primes = 1;
		for(int i = 3; i <= n; i += 2){
			if(is_prime(primes, i)){
				num_primes++;
				if(i > primes.back()){
					primes.push_back(i);
				}
			}
		}

		std::cout << num_primes << std::endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
typedef pair<int,int> pii;

inline bool IN(int x, int y, int w, int h)
{
    return 0 <= x && x < w && 0 <= y && y < h;
}


int main()
{
	int n;
	vi pn(1000000,1);
pn[0]=0;
pn[1]=0;
for(int i=2;i<=1000000/2;i++){
	if(pn[i]==1){
		for(int j=2;j<=1000000/i;j++){
			pn[j*i]=0;
		}
	}
}
	while(cin >> n){
		int ans=0;
		rep(i,n+1){
			if(pn[i])ans++;
		}
		cout << ans << endl;
	}


}

C++: #include <stdio.h>

int isPrime(int n);

int main(void){
    int n;
    int cnt;

    while (scanf("%d", &n)!= EOF){
        cnt = 0;
        for(int i=2; i<=n; i++){
            if (isPrime(i)) cnt++;
        }
        printf("%d\n", cnt);
    }

    return 0;
}


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

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



bool IsPrime[1000010];  //保证不做素数的倍数
int Prim[1000010];   //存素数
void euler_prime(int n){
    int num = 0, j;
    for(int i = 2; i <= n; i ++){
        if(!IsPrime[i])   //不是目前找到的素数的倍数    1不是素数
            Prim[num ++] = i;  //记录质数
        for(j  = 0; j < num; j ++){
            if(i * Prim[j] > n)
                break;
            IsPrime[i * Prim[j]] = true;  //筛;//找到的素数的倍数不访问
            if(i % Prim[j] == 0)
                break;  //i可以看做prime[j]*某个数， i*prime[j+1]就可以看做 prime[j]*某个数*prime[j+1] 。而 prime[j] 必定小于 prime[j+1]，所以 i*prime[j+1] 必定已经被 prime[j]*某个数 筛掉，就不用再做了（等到i=6即最大合因子时会筛掉）
        }
    }
}

int setans(int x)
{
    int cnt = 0;
    for(int i=2; i<=x; i++) {
        if(!IsPrime[i])
            cnt++;
    }
    return cnt;
}
int main()
{
    int n;
    euler_prime(1000005);
    while(scanf("%d",&n))

        printf("%d\n",setans(n));

    return 0;
}

C++: #include<iostream>
#define N 999999
int p[(N+1)/2];int m[N+1];int mk();using namespace std;int main(){int n;p[0]=2;m[1]=0;m[2]=1;mk();while(cin>>n){cout<<m[n]<<'\n';}return 0;}int mk(){int i,j,e=1;for(i=3;i<N;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;}}