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 <iostream>
#include <cmath>
using namespace std;

const int N = 1000010;

bool prime[N];
int number[N];
void init() {
  for (int i=0;i<N;i++) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i=0;i<=sqrt(N);i++) {
    if (prime[i]) {
      for (int j=i*2;j<N;j+=i) prime[j] = false;
    }
  }
  number[0] = 0;
  for (int i=0;i<N-1;i++) {
    number[i + 1] = number[i] + prime[i + 1];
  }
}

int main() {
  int n;
  init();
  while (cin >> n) {
    cout << number[n] << endl;
  }
}

C++: #include <stdio.h>

int main(void)
{
	int n;
	scanf("%d", &n);
	
	bool *d = new bool [n+1];
	int count = 0;

	for(int i = 0; i <= n; i++)
		d[i] = true;

	for(int i = 2; i <= n; i++){
		if(d[i]){
			count++;
			for(int j = i*2; j <= n; j+=i)
				d[j] = false;
		}
	}
	printf("%d\n", count);



	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 (cin>>n) {
		int i = 0;
		while (prime[i] <= n) {
			i++;
		}
		cout << i << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n;
  int cont;
  while(scanf("%d",&n)!=EOF){
    int a[1000000]={0};
    int cont=0;
    a[1]=1;
    for(int i=2;i<=sqrt(n);i++){
      if(a[i]==0){
      for(int j=2;j<=n;j++){
	a[i*j]=1;
      }
    }
    }
    for(int i=1;i<=n;i++){
      if(a[i]==0)cont++;
    }
    cout<<cont<<endl;
  }
}

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

using namespace std;

int main(){
}

C++: #include<iostream>
#define N_MAX 999999

int prime[( N_MAX + 1 ) / 2 ];
int memo[ N_MAX + 1 ];

int mkprime( void );

int main( void )
{
	int n, i, result;

	prime[0] = 2;

	mkprime();

	while( std::cin >> n ){
		std::cout << memo[n] << std::endl;
	}
	
	return 0;
}

int mkprime( void ){
	int i, j, endindex = 1;

	for( i = 3; i < N_MAX + 1; i++ ){
		if( i % 2 == 1 ){
			for( j = 0; j < endindex; j++ ){
				if( i % prime[j] == 0 ){
					break;
				}
			}
		}

		if( prime[j] == 0 ){
			prime[ endindex ] = i;
			endindex++;
		}

		memo[i] = endindex;
	}
}

C++: #include<iostream>
#include<vector>
#include<string>
#define T 1000000
using namespace std;

signed main() {
	vector<bool>hantei(T, true);
	vector<int>sosuu(T);
	int s = 0;
	for (int a = 2; a < T; a++) {
		if (hantei[a]) {
			s++;
			for (int b = a * 2; b < T; b+=a)hantei[b] = false;
		}
		sosuu[a]=s;
	}
	while (cin >> s)cout << sosuu[s] << endl;
}

C++: #include <iostream>

using namespace std;

void solve(int n) {
	int prime[n];
	int j=0;
	for (int i=2; i<=n; i++) {
		prime[j] = i;
		j++;
	}
	int p;
	for (int i=0; i<n; i++) {
		p = prime[i];
		if (p == -1) continue;
		for (int k=i+1; k<n; k++) {
			if (prime[k]%p == 0)
				prime[k] = -1;
		}
	}
	int count = 0;
	for (int i=0; i<n; i++)
		if (prime[i] != -1) count++;
	cout << count << endl;
}

int main() {
	int n;
	while (cin >> n) {
		if (n<=1) cout << 0 << endl;
		solve(n);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define MAX 999999
bool flag[MAX+1];

void check_prime_num(int x){

  int way = sqrt(x);

  for(int i=2;i<way+1;++i) {
    if(x%i==0) break;
    else if(way==i) flag[x] = true;
  }

}

int solve(int n){

  int cnt = 0;

  for(int i=0;i<=n;++i){
    if(flag[i]) ++cnt;
  }

  return cnt;
}

int main(){

  int n;

  memset(flag, false, MAX);
  flag[2] = true; flag[3] = true;

  for(int i=4;i<=MAX;++i){ check_prime_num(i); }

  while(cin>>n){ cout << solve(n) << endl; }

}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define F first
#define S second
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30, Array = int(1e5);
int main(){
  int n, i, j, sum;
  bool jud;
  while(cin >> n){
    sum = 0;
      for(i = 2;i <= n; i++){
        jud = 0;
        for(j = 2;(j * j) <= i; j++){
          if(i == j)  continue;
          if(!(i % j)){
            jud = 1;
            break;
          }
        }
        if(!jud)
          sum++;
      }
      cout << sum <<endl;
  }
}

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

int prime[1000000];


bool isPrime(int n) {
  int x = sqrt(static_cast<double>n);
  for (int i = 3; i <= x; i += 2) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

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

int main(){
int n;
int b;
int c;
int d;
while(cin >> n){
int a[n+1];
b=1;
while(b<n+1){
a[b]=0;
b=b+1;}
a[1]=1;
d=0;
b=2;
while(b<n+1){
if(a[b]==0){d=d+1; c=2; while(1){if(c*b>n){break;} a[c*b]=1; c=c+1;}}
b=b+1;}
cout << d;}


}