Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

C++: #include<iostream>
#include<string.h>
using namespace std;
const int N=1000000;
bool isprime[N];
int prime[N];
int k=0;
void init()
{
    isprime[0]=isprime[1]=false;
    for(int i=2;i<N;i++)
    {
        if(isprime[i]) prime[k++]=i;
        for(int j=0;j<k;j++)
        {
            int d=i*prime[j];
            if(d>=N) break;
            isprime[d]=false;
            if(i%prime[j]==0) break;
        }
    }
}
int main()
{
    int n;
    memset(isprime,true,sizeof(isprime));
    init();
    while(cin>>n)
    {
        int i;
        for(i=0;i<k;i++)
            if(n<prime[i])
                break;
        cout<<i<<endl;
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int n;
	while(cin>>n)
	{
		int count = 0;
		bool *flag = new bool[n+1]();
		for(int i=2;i<n;++i)
		{
			if (flag[i])
			{
				continue;
			}
			for(int j=i*2;j<n;j+=i)
			{
				flag[j] = true;
			}
		}
		flag[0]=true;flag[1]=true;
		for(int i=0;i<=n;++i)
		{
			if(!flag[i])
			{
				++count;
			}
		}
		cout<<count<<endl;
	}
}

C++: // PrimeNumber.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int n, count,k;

	while(cin >> n){
		count = 1;
		k = 0;

		for(int i = 3; i <= n; i += 2){
			for(int j = 3; j <= sqrt((double)i); j += 2)
			{
				if(i%j == 0){
					k = 1;
					break;
				}
			}
			if(k == 0){
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: //筛法也快不到哪里去啊
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
bool prime(int cur)
{
    if(cur==1||cur==0)return false;
    for(int i=2;i<=sqrt(cur);i++)
    {
        if(cur%i==0)
        {
            return false;
        }
    }
    return true;
}
int cnt[1000005];
int main()
{
    for(int i=1;i<=1000005;i++)
    {
        if(prime(i))cnt[i]=cnt[i-1]+1;
        else cnt[i]=cnt[i-1];
    }
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        cout<<cnt[n]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#include <vector>
using namespace std;
bool flag[10000000];
int n, hasil;
int main(){

	for(int i = 1; i <= 1000000; i++){
		flag[i] = true;
	}
	for(int i = 2; i <= 1000; i++){
		if(flag[i] == true){
			for(int u = i*i; u <= 1000000; u = u + i){
				flag[u] = false;
			}
		}
	}
	flag[1] = false;
	while(cin >> n){
		hasil = 0;
		for(int i = 1; i <= n; i++){
			if(flag[i])
				hasil++;
		}
		cout << hasil << endl;
	}
	return 0;
}

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

int main(){
  int n,prime[1000001],key,lf=0;
  prime[0]=2;
  key=1;
  for(int i=3;i<=1000000;i+=2)
    {
      for(int j=2;j<=sqrt(i);j++)
	{
	  if(i%j == 0)
	    {
	      lf=1;
	      break;
	    }
	}
      if(lf == 1)
	{
	  lf=0;
	}
      else 
	{
	  prime[key]=i;
	  key++;
	}
    }

  while(cin >> n)
{
  int cou=0;
  for(int i=0;;i++)
    {
      if(prime[i] <= n)
	{
	  cou++;
	}
      else break;
    }

  cout << cou << endl;
 }
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool isPrime(int x)
{
	if (x < 2)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	for (int i = 3; i <= (int)sqrt(x); i+=2)
		if (x%i == 0)
			return false;
	return true;
}
int main()
{
	int n;
	cin >> n;
	int count = 0;
	for (int i = 1; i <= n; i++)
		if (isPrime(i))
			count++;
	cout << count << endl;
}

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

using namespace std;

int main()
{
	unsigned int  n;
	cin >> n;
	unsigned  int num, count = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> num;
		for(int j = 2; j < num; j++)
		{
			if(num % j == 0)
			{
				break;
			}
			if(num - 1 == j)
			{
				count++;
			}
		}
		if(num == 2)
		{
			count++;
		}
	}
	cout << count << std::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*2; j<1000000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n/2+1; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main (){
    
    /*?´???°???????´?????????????*/
    vector<int>Primenumber(MAX+1,0);
    /*?´???°???????´???????????????????*/
    int n;
    while(cin >> n){
        bv check(MAX+1,true);
    for(int i = 2; i<=n;i++){
        if(check[i]){
            /*true?????£?????¨???????????°????????????false??§*/
            for(int j = 2;i*j<=n;j++)
                check[i*j] = false;
        }
    }
    int ans = 0;
    for(int i = 2;i<=n;i++)
        if(check[i])
            ans++;
    cout << ans << endl;
    }
}

C++: #include"stdio.h"
#define nmax 1000000
int ans[nmax];
bool is_prime[nmax + 1];

void sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = 0;
	ans[0] = ans[1] = 0;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			p++;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
		ans[i] = p;
	}
}
int main()
{
	sieve(nmax);
	int n,m=0;
	for (; scanf("%d", &n) == 1;) {
		printf("%d\n", ans[n]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int prime[100000] = {0};

void makeprime(long long int n)
{
    int k = 1;
    prime[0] = 2;
    for (long long int i = 3; i < n; i++)
    {
        double temp = sqrt(i);
        for (int j = 0; i % prime[j] != 0; j++)
        {
            if (temp < prime[j])
            {
                prime[k++] = i;
                break;
            }
        }
    }
    // rep(i,1000){
    //     cout<<prime[i]<<" ";
    // }
}

int main()
{
    makeprime(999999);
    int n;
    int i;
    while (cin >> n)
    {
        i = 0;
        while (true)
        {
            if (n < prime[i])
            {
                break;
            }
            i++;
        }
        cout << i << endl;
    }
    return 0;
}

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