Go: package main

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

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int ans[999999];

bool isprime(int n) {
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for(int i = 3; i <= sqrt(n); i+=2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    FOR(i, 1, 999999) {
        ans[i] = ans[i-1] + isprime(i+1);
    }
    int i;
    while(cin >> i) {
        cout << ans[i-1] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;
int sieve(int n);
int prime[1000000];
bool is_prime[1000000];

int main()
{

	int p = 0;
	for (int i = 0; i <= 999999; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 999999; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= 999999; j += i) {
				is_prime[j] = false;
			}
		}
	}
	int n;
	while (scanf_s("%d", &n) != EOF) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

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

int main(){
	char nums[1000000];
	int n;
	for(int i = 2; i < 1000000; i++)
		nums[i] = 1;
	for(int j = 2; j < 1000; j++)

		for(int k = 2; j * k <= 1000000; k++)
			nums[j * k] = 0;
	while(cin >> n){
		int count = 0;
		for(int l = 2; l <= n; l++)
			if(nums[l])
				count++;
		cout << count << endl;
	}
	return 0;
}

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

int main()
{
	bool isPrime[1000000];
	int num[1000000];
	memset(isPrime,false,sizeof(isPrime));
	isPrime[0]=isPrime[1]=true;
	for (int i = 2; i < 1000000; i++) {
		if(isPrime[i])
		{
			num[i]=num[i-1];
			continue;
		}

		for(int j=i*2;j<1000000;j+=i)
		{
			isPrime[j]=true;
		}
		num[i]=num[i-1]+1;
	}

	int n;
	while(cin>>n) cout<<num[n]<<endl;
	return 0;
}

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

bool isprime(int x) {
	if (x == 2)
		return true;
	if ((x < 2) || (x % 2 == 0)) {
		return false;
	}
	int i = 3;
	while (i == sqrt(x)) {
		if (x%i == 0)
			return false;
		i = i + 2;
	}
	return true;
}

int main()
{
	
	int n;
	while (cin >> n) {
		int C = 0;
		for (int i = 0; i <= n; i++) {
			if (isprime(i) == true)
				C++;
		}
		cout << C<<endl;
	}
	return 0;
}

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

int sieveOfEratosthenes(int n) {
    vector<int> prime;
    vector<int> isPrime((unsigned long)n + 1, true);
    isPrime[0] = false, isPrime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (isPrime[i]) {
            prime.push_back(i);
            for (int j = 2 * i; j <= n; j+= i)
                isPrime[j] = false;
        }
    }
    return (int)prime.size();
}

int main() {
    int n;
    while (cin >> n) {
        cout << sieveOfEratosthenes(n) << endl;
    }
    return 0;
}

C++: #include <cstdio>
int d[1000000],c[1000000];
int main() {
	int i,j,r=0,n;
	for(i=2;i<500000;i++) {
		if(d[i]){c[i]=r;continue;}
		c[i]=++r;
		for(j=i*2;j<=999999;j+=i)d[j]=1;
	}
	while(scanf("%d",&n)!=EOF) {
		printf("%d\n",c[n]);
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <fstream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 0x3f3f3f3f
#define inff -30000000
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
const int MAX=1e6+10;
int prime[MAX];
bool notprime[MAX];
int num=0;
void init(){
    memset(notprime,0,sizeof(notprime));
    for(int i=2;i*i<=MAX;i++){
        if(!notprime[i]){
            prime[num++]=i;
            for(int j=i*i;j<=MAX;j+=i)
                notprime[j]=1;
        }
    }
}
int main(){
    #ifdef SIYU
    freopen("in.txt","r",stdin);
    #endif // SIYU
    int n;
    init();
    while(cin>>n){
        int *p=upper_bound(prime,prime+num,n);
        int ans=p-prime;
        cout<<ans<<endl;
    }
    return 0;
}

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

int prime(int number) {
    int s_num = sqrt(number);
    if (number == 2) {
        return 1; 
    } else if (number % 2 == 0) {
        return 0;
    }
    for (int i = 3; i <= s_num; i += 2) {
        if (number % i == 0) {
            return 0;
        }
    }
    return 1;
}

int main(void) {
    int number;
    int count;

    while (std::cin >> number) {
        count = 0;
        for (int i = 2; i <= number; i++) {
            if (prime(i) == 1) {
                count++;
            }
        }
        std::cout << count << std::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;

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

	return 0;
}

C++: #include<iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main()
{
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	primesum[0] = 0;
	primesum[1] = 0;
	primesum[2] = 1;

	for (int a = 3; a<1000000; a++)
	{
		prime[a] = 1;
	}

	for (int a = 3; a<1001; a++)
	{
		if (checked[a] == 0)
		{
			checked[a] = 1;
			for (int b = 2; b<a; b++)
			{
				if (a%b == 0)
				{
					prime[a] = 0;
					break;
				}
			}
			if (prime[a] == 1)
			{
				for (int c = 2 * a; c<1000000; c += a)
				{
					checked[c] = 1;
					prime[c] = 0;
				}
			}
		}
	}

	for (int a = 3; a<100; a++)
	{
		primesum[a] = primesum[a - 1] + prime[a];
		cout << "prime[" << a << "] = " << prime[a] << endl;
		cout << "primesum[" << a << "] = " << primesum[a] << endl;
	}

	while (cin >> n)
	{
		cout << primesum[n] << endl;
	}

	return 0;
}