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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+10;
const int maxn=100000+5;
int prime[maxn];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt++]=i;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAX 1000000
bool prime[MAX];
int main(void){ 
  
  prime[0] = prime[1] = false;
  //memeset(prime,sizeof(prime),true);
  fill(prime,prime+MAX,true);
  long long int ans[MAX];
  
  ans[0] = ans[1] = 0;
  ans[2] = 1;
  int now=0;
  
  for(long long int i = 2 ; MAX >= i ; i ++){
    ans[i] = now ;
    //cout<<now<<" "<<ans[i]<<endl;
    if(prime[i]){
      //cout<<i<<endl;
      now ++;
      for(long long int j = i + i ; MAX > j ; j += i){
	prime[j] = false;
      }
    }
  }
  
  long long int n;
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  
}

C++: #include<cstdio>
#define MAX 1000010

bool is_prime[MAX];

int sieve(int n) {
	for (int i = 0; i <= n; ++i) is_prime[i] = true;	
	is_prime[0] = is_prime[1] = false;
	int count = 0;
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) {
			++count;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return count;
}

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

C++: #include <stdio.h>
int isprime(int n){
	int i,j;
	int isprime[10000];
	for(i=0;i<=10000;i++){
 		isprime[i]=1;
	}
	isprime[0]=isprime[1]=0;
	for(i=2;i<=10000;i++){
 		if(isprime[i]==1){
 			for(j=2*i;j<=1000;j+=i){
				isprime[j]=0;
			}
		}
	}
}

int main(){
	int a,b,i,n,p1,q1;
	scanf("%d", &n);
	while (n != 0){
		for(i=2;i<=n;i++){
			a = isprime(i-2);
			b = isprime(i);
			if(a==1 && b==1){
				p1 = i-2;
				q1 = i;
			}
		}
		printf("%d %d\n",p1,q1);
		scanf("%d", &n);
	}
	return 0;
 }

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

int sos(int);

int pri[10000000];

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

int sos(int a){
  int i,j,c=0,b;
  for(j=2;j<=a;j++){
    b=0;
    if(pri[j]==3)continue;
    for(i=2;i<=sqrt(j);i++){
      if(j%i==0){pri[j]=3;b=1;break;}
      
    }
    if(b==0){pri[j]=1;c++;}
  }
  return c;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

bool debug=false;
/*---------------------------------------------------*/


int prime[1000000];
bool is_prime[1000000];

void sieve(){
  int p=0;
  for(int i=0;i<1000000;i++)is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<1000000;i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<=1000000;j+=i)is_prime[j]=false;
    }
  }
}


int main(){
  int n,cnt;
  sieve();
  while(cin>>n){
    cnt=0;
    for(int i=0;;i++){
      if(prime[i]>n)break;
      cnt++;
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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;
}