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>
using namespace std;

const int N = 1000000;
bool flags[N];
int  counts[N];

void make_flags_and_counts ();

void make_flags_and_counts () {
    fill(flags, flags + N, true);
    flags[0] = false;
    flags[1] = false;

    fill(counts, counts + N, 0);
    for (int i = 2; i < N; ++i) {
        if (flags[i]) {
            for (int j = 2; i*j < N; ++j) {
                flags[i*j] = false;
            }
        }
        counts[i] = flags[i] ? counts[i-1] + 1 : counts[i-1];
    }
}

int main() {
    make_flags_and_counts();

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

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0,k;
	while(k<29){
		cin >> N;
		count = 0;
		if(N<0)	break;
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
		k++;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n){
for(int i=2;i*i<=n;i++){
if(n % i == 0) return false;
}
return n!=1;
}

int main(){
int n;

while(~scanf("%d",&n)){
int* table =  new int[1000000];
memset(table,sizeof(table),1);
table[0]=0;

for(int i=1;i<=n;i++){
if(!is_prime(i)) {
for(int j=i;j<=n;j*=i){
table[j] = 0;
}
}
}
printf("%d\n",count(table,table+1000000,1));
}
}

C++: #include <iostream>

using namespace std;

int count_prime(int n)
{
    int c = 0;
    bool ps[n+1];

    ps[0] = false;
    ps[1] = false;

    for(int i = 2; i <= n; ++i)
        ps[i] = true;

    for(int i = 2; i <= n; ++i){
        if(ps[i]){
            for(int j = i * 2; j <= n; j += i)
                ps[j] = false;
        }
    }

    for(int i = 1; i <= n; ++i){
        if(ps[i])
            ++c;
    }
    return c;
}

int main()
{
    int n;
    int c;

    while(cin >> n){
        c = count_prime(n);
        cout << c << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string.h>
using namespace std;
int n,ans;
bool a[1000000];
int main(){
	while(cin>>n){
		memset(a,true,sizeof(a));
		a[0]=false;
		a[1]=false;
		ans=0;
		for(int i=2;i<=n;i++){
			if(a[i])
				for(int j=2*i;j<=n;j+=i)
					a[j]=false;
		}
		for(int i=1;i<=n;i++)
			if(a[i]) ans++; 
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
using namespace std;
 
static const int MAX = 10;

int main() {
    static bool is_prime[MAX] = { false };
    static int npr[MAX];
    for (int i = 2; i<MAX; i++) {
        if (!is_prime[i]) {
            for (int j = 2; j*i<MAX; j++) {
                is_prime[i*j] = true;
            }
        }
        npr[i] = npr[i - 1] + !is_prime[i];
    }
    int n;
    while (cin >> n) {
        cout << npr[n] << endl;
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<functional>
#include<queue>
#include<stack>
#include<math.h>
#define INF 999999

using namespace std;

typedef long long ll;

int main()
{
	int n;
	
	while (cin >> n) {
		int count = 0;
		for (int i = 2; i <= n; i++) {
			int ope = 1;
			for (int j = 2; j*j <= i; j++) {
				if (i%j == 0) {
					ope = 0;
					break;
				}
			}
			count += ope;
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int num[1000001]={};
int main ()
{
int p,n,m,cou;m=0;cou=0;p=3;


for(int i=2;i<=1000000;i++)
	num[i]=1;
for(int i=2;i<=1001;i++){
for(int k=2;k*k<=i;k++){
if(i%k==0){num[i]=0;}}
}
while(scanf("%d",&n)!=EOF)
{
for(int i=2;i<=n;i++)
	cou+=num[i];

if(n==2)cou=1;
if(n==1)cou=0;
//else cou++;
printf("%d\n",cou);
cou=0;
}
return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int n,i,j,z,x;
	
    scanf("%d",&n);
	while(n<2){
		for(i=2;i<=n;i++){
			z=0;
			for(j=2;j<=i;j++){
				if(i%j==0 && i!=j){
					z++;
					break;
				}
			}
			if(z==0){
				x++;
			}
		}
		printf("%d\n",x);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>

using namespace std;

int ans = 0;

void Prime_number(int n){
	int i;
	int prime_num;

	for(i = 2; ; i++){
		if(n % i == 0 && n != i){
			break;
		}else if(n == i){
			ans++;
			break;
		}
	}

	if(n != 2){
		Prime_number(n-1);
	}
}

int main(){
	int n;

	while((scanf("%d",&n)) != EOF){
		Prime_number(n);
		cout << ans << endl;
		ans = 0;
	}

}

C++: #include <cstdio>
#include<iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <string.h>
#include<vector>
#include <set>
#include <vector>
#include <iterator>
using namespace std;
typedef long long int ll;
const int MAX_N = 999999 + 5;

int prime[MAX_N + 1];
int is_prime[MAX_N + 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] = false;
    for (int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            //cout << "**" << endl;
            prime[i] = ++p;
            for (int j = 2 * i; j <=  n; j += i)
                is_prime[j] = false;
        }
        else prime[i] = p;
    }
    return ;
}
int main()
{
    int a;
    sieve(999999);
    while (~scanf("%d", &a))
    {
        printf("%d\n", prime[a]);
    }
    return 0;
}

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

using namespace std;

bool isPrime(int x)
{
	bool is_prime = true;
	if (x == 1) is_prime = false;
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
		{
			is_prime = false;
			break;
		}
	}
	return is_prime;
}

int countPrime(int x, vector<int> &plist)
{
	int count = 0;
	for (int i = 2; i <= x; i++)
	{
		if (plist[i] == 0) continue;
		if (isPrime(i))
		{
			count++;
		}
		else
		{
			for (int j = i; j < x; j += i)
			{
				plist[j] = 0;
			}
		}
	}
	return count;
}

int main()
{
	int n;
	vector<int> plist(1000000, 1);
	while (cin >> n, !cin.eof())
	{

		cout << countPrime(n, plist) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int n, i, cnt, num[999999];

bool is_prime(int k)
{
	if(k == 1)  return false;
	if(k == 2)  return true;
	for(int i = 2; i*i <= k; i++){
		if(k%i == 0)  return false;
	}
	return true;
}

int count_prime()
{
	for(i = 1; i <= 999999; i++){
		if(is_prime(i))  cnt++;
		num[i] = cnt;
	}
	return 0;
}

int main()
{
	count_prime();
	while(scanf("%d", &n) != EOF){
		printf("%d\n", num[n]);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  vector<int> v;
  v.resize(999999);
  fill(v.begin(), v.end(), 1);
  v[0] = 0;
  v[1] = 0;
  for (int i = 0; i * i < v.size(); ++i) {
    while (v[i] == 0) ++i;
    for (int m = i + 1; m < v.size(); ++m) {
      if (m % i == 0) {
        v[m] = 0;
      }
    }
  }
  while (cin >> n) {
      cout << accumulate(v.begin(), v.end() - (v.size() - (n + 1)), 0) << endl;
  }
  return 0;
}