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++: #include <iostream>
#include <math.h>
using namespace std;

int main() {
int b[1000000];
for (int k=0;k<1000001;k++){
	b[k]=0;
}
b[2]=1;
b[3]=1;
b[4]=0;
b[5]=1;
b[6]=0;
b[7]=1;

for (int p=10;p<1000001;p++){
int i,a=0 ;
	i=3;
	while(i<sqrt(p)){
		if(p%i==0){
			break;
	}i=i+2;
	}
	if (i>=sqrt(p)){
		a=1;
	}
	b[p]=a;
}
int c[1000000];
for (int l=0;l<1000001;l++){
	c[l+1]=c[l]+b[l+1];
}
int r;
while(cin>>r){
	cout<<c[r]<<endl;
}
	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int head,fin;
	int temp = 0;
	
	while(cin>>n)
	{
		vector<int> isPrime(n,1);
		
		isPrime[0] = isPrime[1] = 0;
		
		for(;;){
			//TõXgÌæªð©Â¯é
			for(head = temp+1; head < n; head++){
				if(isPrime[head] == 1){
					break;
				}
			}
			
			//æªðÜÜÈ¢{ÍSÄ¬
			for(int i = head; i < n; i++){
				isPrime[i*head] = 0;
			}
			
			//TõXgÌÅãÖ
			for(fin = n; fin > 0; fin--){
				if(isPrime[fin] == 1){
					break;
				}
			}
		//	printf("head:%d    fin:%d\n",head,fin);
			
			if(fin < head*head){
				break;
			}
			temp = head;
		}
		int cont = 0;
		
		for(int i = 0; i < n; i++){
			if(isPrime[i] == 1){
				cont++;
			}
		}
		printf("%d\n",cont);
	}
}

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

using namespace std;


int main(){
	int n;

	while(cin >> n){
		int ans=0;

		for(int number=2;number<=n;number++){
			int flag = 0;
			for(int i=2;i<number;++i){
				if(number%i==0){
					flag = 1;
					break;
				}
			}
			if(flag==0)ans++;
		}
		printf("%d\n",ans);
	}


	return 0;
}

C++: //#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int long long
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

bool isprime[1000000];
int ans[1000000];

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	rep(i, 0, 1000000)isprime[i] = true;
	isprime[0] = false;
	isprime[1] = false;
	ans[0] = ans[1] = 0;
	int n = 0;
	rep(i, 2, sqrt(1000000) + 1)
	{
		if (isprime[i])
		{
			for (int j = 2 * i; j < 1000000; j += i)
			{
				isprime[j] = false;
			}
		}
	}
	rep(i, 2, 1000000)
	{
		if (isprime[i])
		{
			n++;
		}
		ans[i] = n;
	}

	int N;
	while (cin >> N)
	{
		cout << ans[N] << endl;
	}

	return 0;
}

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

using namespace std;
#define MAX_NUM 1000010


void do_calc(int *numPrime){
  for(int i=2;i<=MAX_NUM;i++){
    bool flag = false;

    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0){
	flag = true;
	break;
      }
    }
      
    if(flag){
      numPrime[i] = numPrime[i-1];
      continue;
    }else{
      numPrime[i] = numPrime[i-1] + 1;
    }
  }
}
  


int main(){
  int n;
  int numPrime[MAX_NUM];

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

C++: #include<memory.h>
#include<cstdio>
const int maxn=100000;
int x;
bool isPrime[maxn];
void generateprime()
{

    memset(isPrime,true,sizeof(isPrime));
    for(int i=2;i<maxn;i++)
        for(int j=2;j*i<maxn;j++)
        isPrime[j*i]=false;
}

int main()
{
    generateprime();
    while(scanf("%d",&x)!=EOF)
    {   int res=0;
        for(int i=2;i<=x;i++)
            if(isPrime[i])
            {
            res=res+1;}
        printf("%d\n",res);
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    double he=0;
    while(cin>>n){
        he=sqrt(n);
        int ser[n+1];
        for(int i=2;i<=n;i++)ser[i]=1;
        for(int i=2;i<=he;i++)if(ser[i]==1)for(int j=2;j*i<=n;j++)ser[i*j]=0;
        for(int i=2;i<=n;i++)if(ser[i]==1)co++;
        cout<<co<<endl;
        co=0;
    }
}

C++: /*Filename: aoj0009.cpp
 *Author: Mushiyo
 */

#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

const int size = 999999 + 1;
bool isPrime[size];
vector<int> prime;

void sieveOfEratosthenes() {
	for (int i = 2; i < size; ++i) {
		isPrime[i] = true;
	}

	int sqrtSize = sqrt(size) + 1;

	for (int i = 2; i < sqrtSize; ++i) {
		if (isPrime[i] == true) {
			for (int j = i * i; j < size; j += i) {
				isPrime[j] = false;
			}
		}
	}

	for (int i = 2; i < size; ++i) {
		if (isPrime[i]) {
			prime.push_back(i);
		}
	}
}

int main() {
	sieveOfEratosthenes();

	int n = 0;

	while (cin >> n) {
		int countPrime = 0;

		for(int i = 0; i < prime.size(); ++i){
			if(prime[i] > n){
				break;
			}
			else{
				++countPrime;
			}
		}

		cout << countPrime << endl;
	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
int pri[1000000];
int main()
{
    int i,j;
    memset(pri,0,1000000*sizeof(int));
    for (i=2;i<=1000;i++)
    {
        for (j=i*i;j<1000000;j=j+i)
        {
            pri[j]=1;
        }
    }
    int n;
    while (scanf("%d",&n)!=EOF)
    {
        int sum=0;
        for (i=2;i<=n;i++)
            if (pri[i]==0) sum++;
        printf("%d\n",sum);
    }
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

vector<bool> eratosthenes_sieve(size_t size) {
  vector<bool> is_prime(size + 1, true);
  for (size_t i = 0; i <= size; i++) {
    if (i < 2) {
      is_prime[i] = false;
    } else if (is_prime[i]) {
      for (size_t j = 2 * i; j <= size; j += i) {
        is_prime[j] = false;
      }
    }
  }
  return is_prime;
}

int main() {
  int n = 1'000'000 - 1;
  auto sieve = eratosthenes_sieve(n);
  vector<int> acc(n + 1, 0);
  rep(i, n) { acc[i + 1] = acc[i] + (sieve[i + 1] ? 1 : 0); }

  int m;
  while (cin >> m) {
    cout << acc[m] << "\n";
  }
  return 0;
}

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

int Prime[NUM];

int main(){

	for( int i=0;i<NUM;i++ ){
		Prime[i]=1;
	}
	Prime[0]=Prime[1]=0;
	for( int i=2;i<NUM;i++ ){
		if( Prime[i] ){
			for( int j=i*2;j<NUM;j+=i ){
				Prime[j]=0;
			}
		}
	}
	int n;
	while( cin>>n ){
		int primenum=0;
		for( int i=0;i<=n;i++ ){
			primenum+=Prime[i];
		}
		cout<<primenum<<endl;
	}

	return 0;
}