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<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n,ans;

int main(){
    int N=1000000;
    int prime[N];
    rep(i,N) prime[i] = 1;
    prime[0] = prime[1] = 0;
    rep(i,N){
        if(prime[i]){
            for(int j = i + i; j < N; j+=i){
                prime[j] = 0;
            }
        }
    }
    while(cin>>n){
        ans=0;
        rep(i,n+1)ans+=prime[i];
        out(ans);
    }
}

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; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

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

struct IsPrime {
 public:
  explicit IsPrime(int max);
  bool operator()(int n);

 private:
  std::vector<bool> is_prime;
};

IsPrime::IsPrime(int max) : is_prime(max + 1, true) {
  is_prime[0] = false;
  is_prime[1] = false;
  for (auto i = 2; i <= std::sqrt(max); i++) {
    if (!is_prime[i]) {
      continue;
    }

    for (auto mult = 2 * i; mult <= max; mult += i) {
      is_prime[mult] = false;
    }
  }
}

bool IsPrime::operator()(int n) { return is_prime[n]; }

int CountPrime(IsPrime& is_prime, int upto) {
  int cnt = 0;
  for (int i = 2; i <= upto; i++) {
    if (is_prime(i)) {
      cnt++;
    }
  }
  return cnt;
}

int main(void) {
  std::vector<int> inputs;
  int n;
  while (std::cin >> n) {
    inputs.push_back(n);
  }

  int max = *std::max_element(inputs.begin(), inputs.end());
  IsPrime is_prime{max};

  for (auto n : inputs) {
    std::cout << CountPrime(is_prime, n) << '\n';
  }
  return 0;
}

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

bool testinPrimeSet(int num, vector<int> & pset) {
	for (vector<int>::iterator it = pset.begin(); it < pset.end() && sqrt(num) >= (*it); it++) {
		if ((num % (*it) == 0))
			return false;
	}
	return true;
}

int CountPrime(int num, vector<int> & pset) {
	int be = pset.at(pset.size() - 1);
	while (++be <= num) {
		if(testinPrimeSet(be, pset))
			pset.push_back(be);
	}
	return 0;
}

int getdst(int num, vector<int> & pset) {
	int i = 0;
	for (vector<int>::iterator it = pset.begin(); it < pset.end(); it++)
		if ((*it) <= num)
			i++;
		else
			break;
	return i;
}

int main() {
	int n = 0;
	int a[5] = { 2,3,5,7,11 };
	vector<int> dst;
	vector<int> primeset(a, a + 5);
	while (cin >> n) {
		CountPrime(n, primeset);
		dst.push_back(n);
	}
	for (vector<int>::iterator it = dst.begin(); it < dst.end(); it++)
		cout << getdst(*it, primeset) << endl;
	return 0;
}

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

int sieve(int n) {
    if (n <= 1) return 0;
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;

    int res = 0;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            res++;
            for (int j = i+i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

int main() {
    while (1) {
        int n;
        int ret = scanf("%d", &n);
        if (ret < 0) break;
        printf("%d\n", sieve(n));
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int a[1000000];
void sive()
{
    int i,j;
    a[0]=a[1]=1;
    for(i=4;i<=1000000;i+=2) a[i]=1;
    for(i=3;i<=1000;i+=2){
        if(a[i]==0)
        {
            for(j=i*i;j<=1000000;j+=2*i) a[j]=1;
        }
    }
}
int main()
{
    sive();
    int n,i,j=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(a[i]==0) j++;
    }
    cout<<j<<endl;

    return 0;
}

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;
        int ans=0;
        for(int i=0;i<num;i++){
            if(prime[i]<=n)
                ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}

C++: #pragma  warning (disable:4996)
#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;
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++){
		if (!vis[i]){

			prime[i] = 1;
			for (int j = i + i; j <= n; j += i){
				vis[j] = 1;
				prime[j] = 0;

			}
		}
	}
	int sum = 0;
	for (int i = 2; i <= n; i++){
			if (prime[i]){
				sum++;
			}
		}
		cout << sum << endl;
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(int argv,char* argv[]){
unsigned x[30];
int count=0;
for(int i=0;i<argv;I++){
cin>>x[i];
}
for(int i=0;i<argv;i++){
for(int j=1;j<x[i];j++){
if(x[i]%j!=0)
count++;
}
cout<<count<<endl;
count=0;
}
return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

int n;
int main()
{
	bool prime[1000005];
	memset(prime, true, 1000005);
	prime[0] = false; prime[1] = false;
	for (int i = 2; i*i < 1000005; i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; i*j < 1000005; j++)
			{
				prime[i*j] = false;
			}
		}
	}
	while (cin >> n)
	{
		int cnt = 0;
		REP(i, n+1)
		{
			if (prime[i] == true)
			{
				cnt++;
				//cout << i << endl;
			}
		}
		cout << cnt << endl;
	}

	return 0;
}