Go: package main

import "fmt"

func main() {
	const MAX = 1000000
	prime := make([]int, MAX, MAX)
	check := make([]int, MAX, MAX)
	count := make([]int, MAX, MAX)

	prime[0] = 1
	prime[1] = 1

	// prime init
	for i := 2; i < MAX; i++ {
		if check[i] == 1 {
			continue
		}

		if prime[i] == 0 {
			for j := i * 2; j < MAX; j += i {
				check[j] = 1
				prime[j] = 1
			}
		}
	}

	for i := 2; i < MAX; i++ {
		cnt := 0

		if prime[i] == 0 {
			cnt = 1
		}

		count[i] = count[i-1] + cnt
	}

	for {
		var input int
		inputCount, _ := fmt.Scanf("%d", &input)
		if inputCount != 1 {
			break
		}

		fmt.Println(count[input])
	}
}

C++: int primes[78498], num_primes;
int calculated;
int count_pos(int n) {
	for (int i = 0; i < num_primes; i++) {
		if (primes[i] == n) {
			return i + 1;
		}
		else if (primes[i] > n) {
			return i;
		}
	}
	return num_primes;
}
int main() {
	primes[0] = 2;
	calculated = 2;
	num_primes = 1;
	while (true) {
		int n;
		if (!scanf("%d", &n)) break;
		if (calculated+1 < n) {
			for (int i = calculated + 1; i < n + 1; i += 2) {
				bool is_prime = true;
				int max = (int)(sqrt(i)) + 1;
				for (int j=1; primes[j] < max&&j<num_primes; j++) {
					if (i%primes[j] == 0) {
						is_prime = false;
						break;
					}
				}
				if (is_prime) {
					primes[num_primes++] = i;
				}
			}
			calculated = n - (n % 2);
		}
		printf("%d\n", count_pos(n));
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{

long long  n,f=1,c=0;
cin>>n;
for(long long i=2;i<=n;i++)
{
    if(i==2){f=1;c++;continue;}
    for(long long j=2;j<i;j++)
    {
        if(i%j==0){f=0;break;}
        else f=1;
    }
    if(f==1)c++;
}
cout<<c;
    return 0;
}

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

int a[1000000];

int main()
{
  int n;
  int count;

  for (int i = 2; i < 1000000; i++){
     a[i] = 1;
   }

   for (int i = 0; i * i < 1000000; i++){
     if  (a[i] == 1){
       for (int j = 2; j * i <= 100000; j++){
         a[j * i] = 0;
       }
     }
   }

   while (cin >> n){
     count = 0;
     for (int i = 0; i < 1000000; i++){
       if (a[i] == 1){
         count++;
       }
     }
   }

   cout << n << endl;

   return (1);
}

C++: 
#include<iostream>
#pragma warning(disable:4996)
#define MAX_N 1000000
using namespace std;

int prime[MAX_N];//第i个素数
bool is_prime[MAX_N + 1];//is_pime[i]?true表示i?素数

//返回n以内素数的个数
int 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]){
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i)is_prime[j] = false;
		}
	}
	return p;

}

int main(){
	int n;
	while (scanf("%d", &n) != EOF){
		printf("%d\n", sieve(n));
	}

}

C++: #include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
int prime[maxn];
bool is_prime[maxn];
int sieve(int n) {
	int p = 0;

	for(int i=2; i<=n; i++) {
		if(is_prime[i]) {
			prime[p++] = i;
			for(int j=2*i; j<=n; j+=i) is_prime[j] = false;
		}
	}
	return p;
}
int main() {
	int n;
	for(int i=0; i<=maxn; i++) is_prime[i] = true;
	//0???1???????´???°
	is_prime[0] = is_prime[1] = false;
	while(~scanf("%d",&n)) {

		int p = sieve(n);
		printf("%d\n",p);
	}
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;
#define NUM 1000000
int main(){
	long int n;
	int p[NUM],i,j,k,a,b;
	for(i=0;i<NUM;i++){
		p[i]=0;
	}
	for(i=2;i<NUM;i++){
		if(p[i]==0){
			p[i]=2;
			for(j=2;j<(NUM/i);j++){
				p[i*j]=1;
			}
		}	
	}
	while(cin>>n){
		a=0;
		for(i=2;i<=n;i++){
			if(p[i]==2)a++;
		}
		cout<<a<<endl;
	}
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
const int SIZE = 1000000;
bool mark[SIZE];
long long int num[SIZE];
void findp(){
    memset(mark, true, sizeof(mark));
    for(int i = 2; i <= sqrt(SIZE); i ++){
        if(mark[i]){
            for(int j = i + i; j < SIZE; j += i){
                mark[j] = false;
            }
        }
    }
    num[1] = 0;
    for(int i = 2; i < SIZE; i ++){
        num[i] = num[i-1];
        if(mark[i]){
            num[i] += 1;
        }
    }
}
int main(){
    int n;
    findp();
    while(cin>>n){
        printf("%ld\n", num[n]);
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
bool isprime[1000005];
int prime[1000005];
void sieve() {
	for (int i = 0; i <= 1000000; i++) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	prime[0] = prime[1] = 0;
	for (int i = 2; i <= 1000000; i++) {
		if (isprime[i]) {
			prime[i] = prime[i - 1] + 1;
			for (int j = 2 * i; j <= 1000000; j += i) isprime[j] = false;
		}
		else prime[i] = prime[i - 1];
	}
}
int main() {
	sieve();
	int n;
	while (cin >> n) {
		cout << prime[n] << endl;
	}
}

C++: #include <stdio.h>
#include <iostream>
 
using namespace std;
 
void uru(int c, int d) {
    int counter = 0;
 
    for (int i = c; i <= d; i++) {
        if (i % 4 == 0) {
            if (i % 100 == 0) {
                if (i % 400 == 0) {
                    cout << i << endl;
                    counter++;
                } 
            } else {
                cout << i << endl;
                counter++;
            }
        }
    }
    if (counter == 0) {
        cout << "NA" << endl;
    }
    //cout << endl;
    return;
}
 
int main() {
    int a,b;
 	bool flag=false;
    while (cin >> a >> b) {
    	if (a == 0 && b == 0) {
            break;
        }
    	if(flag) cout<<endl;
            uru(a,b);
    	flag=true;
    }
	//cout<<000000<<endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(void){
  const int n = 1000000;
  bool* check_A = (bool*)malloc(sizeof(bool)*n);
  int*  num_A   = (int*)malloc(sizeof(int)*n);
  int N = 0, temp = 2;
  memset(check_A, true, n);
  check_A[0] = false;
  check_A[1] = false;
  num_A[0] = 0;
  num_A[1] = 0;
  for(int i = 0; i < n; i++){
    if(check_A[i]){
      for(;temp < i;temp++){
	num_A[temp] = N;
      }
      temp++;
      num_A[i] = ++N;
      for(int j = 2; i*j < n; j++){
	check_A[i*j] = false;
      }
    }
  }
  int s;
  while(cin >> s){
    cout << num_A[s] << endl;
  }
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#define N_MAX 1000

using namespace std;

int main(){
	
	int array[N_MAX],i,j,n, num = 0;
	
	while(cin>>n){
		num = 0;
		for (i=0;i<n;i++)
			array[i]=i+2;
		for (i=0;i<n;i++){
			for (j = (i+2); (i+2) * j <= n; j++)
				array[(i+2) * j - 2] = -1;}

	for (i = 0; i < n-1; i++){
    if (array[i] != -1)
	num++;
	}
	cout<<num<<endl;
	}
	cin>>n;
  
	return (0);
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

#define MAX 1000000

static bool gosei[MAX];

void b(){
	for(int i=2;gosei[i]==false&&i<MAX;i++)
		for(int j=2,k;(k=i*j)<MAX;j++)
			gosei[k]=true;
}

int c(int n){
	int cnt=0;
	for(int i=2;i<=n;i++)
		if(!(gosei[i]))cnt++;
	return cnt;
}

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

C++: #include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
 _Bool *list;
 int n,i,j,cnt;
 
 while(scanf("%d",&n) != EOF)
 {
  cnt = 0;
  list = (int*)calloc(n+1,sizeof(int));
  for(i = 2; i <= n; i++)
  {
   if(list[i] != 1) /*prime number:0 no prime numbers:1*/
   { 
    cnt++;
    for(j = i+i; j <= n; j+=i) list[j] = 1;
   }
  }
  printf("%d\n",cnt);
  free(list);
 } 
 return 0;
}