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<cstdio>
const int maxn = 1000010;
int prime[maxn + 10];
int main(){
	for(int i = 2; i <= maxn; i++){
		if(!prime[i]) prime[++prime[0]] = i;
		for(int j = 1; j <= prime[0] && prime[j] <= maxn / i; j++){
			prime[prime[j] * i] = true;
			if(i % prime[j] == 0) break;
		}
	}
	int n;
	while(scanf("%d", &n) == 1){
		int l = 0, r = prime[0] + 1;
		while(r - l > 1){
			int m = (l + r) / 2;
			if(prime[m] <= n) l = m;
			else r = m;
		}
		printf("%d\n", l);
	}
	return 0;
}

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

using namespace std;

int main() {
  bitset<1000000> prime;
  int i, j, n;
  while (cin >> n) {
    prime.reset();
    for (i = 2; i <= n; i++)
      if (prime[i] == false)
	for (j = i + i; j <= n; j += i)
	  prime[j] = true;
    cout << n - prime.count() - 1 << endl;
  }
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,n;
    n=0;
    while ( cin >> a){
        for (int i=2;i<a;i++){
            if (prime(i)==0){
                n++;
            }
        }
        cout << n << endl;
    }
}


int prime(int x){
    if(x==2 || x==3 || x==5 || x==7)
        return 0;
    if(x%2==0)
        return 1;
    if(x%3==0)
        return 1;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 1;
    }
    return 0;
}

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

int main() {
	int n;
	while(cin >> n && n != EOF) {
		bool* prime = new bool[n+1];
		int count = 0;
		for(int i = 0; i <= n; ++i) {
			prime[i] = true;
		}
		prime[0] = prime[1] = false;
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
			//	cout << i << '\t';
				for(int j = 2 * i; j <= n; j += i) {
					prime[j] = false;
				}
			}
		}
		
		for(int i = 0; i <= n; ++i) {
			if(prime[i]) {
				count++;
			}
		}
		
		cout << count << endl;
		delete[] prime;
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

bool Is_Prime(int n){
  if(n==1) return false;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      return false;
    }
  }
  return true;
}
int p[100100];

signed main(){
  loop(i,1,100001){
    if(Is_Prime(i))p[i]=1;
  }
  rep(i,10001)p[i+1]+=p[i];
  int m;
  while(cin>>m){
    cout<<p[m]<<endl;
  }
  return 0;
}

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

bool f[1000000];

int main(){
	int n;
	while(cin>>n){
		memset(f,0,n*sizeof(bool));
		int l=sqrt(n);
		for(int i=2;i<=l;i++){
			for(int j=2;j*i<=n;j++){
				f[j*i]=true;
			}
		}
		int cnt=0;
		for(int i=2;i<=n;i++) if(!f[i])cnt++;
		cout<<cnt<<endl;
	}
}

C++: #include<stdio.h>
int flg[1000000];
int main(void)
{

	int a,i,j,cnt;
	while(scanf("%d",&a)!=EOF){	
		for(i=2;i<=a;i++){
		flg[i]=1;
		}
		for(i=2;i*i<=a;i++){
			if(flg[i]==1){
				j=2;
				while(i*j<=a){
				flg[i*j]=0;
//				printf("i=%d j=%d a=%d\n",i,j,a);
				j++;
				}
			}
		}
//		for(i=2;i<=10;i++)	printf("flg=%d\n",flg[i]);
		cnt=0;
		for(i=2;i<=a;i++){
//		printf("i=%d\n",i);
			if(flg[i]==1){
//			printf("i=%d\n",i);			
			cnt++;
			}
		}
		printf("%d\n",cnt);
	}	
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(int argc,char* argv[]){
unsigned x[30];
int count=0;
for(int i=0;i<argc;i++){
cin>>x[i];
}
for(int i=0;i<argc;i++){
for(int j=1;j<x[i];j++){
if(x[i]%j!=0)
count++;
}
cout<<count<<endl;
count=0;
}
return 0;
}

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

int main()
{
	bool prm[N];
	for(int i=0; i<N; i++)
	{
		prm[i]=true;
		int upto= (int) sqrt(N);
		for(int i=2;i<= upto; i++)
		{
			if(prm[i])
				for(int j=2; j*i<N; j++)
				{
				    prm[i*j]=false;
				}
		}
		int n;
		while(cin>>n)
		{
			int count=0;
			for(int i=2; i<=n; i++)
			{
				if(prm[i])
					count++;
			}
			cout<<count<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#define Number 1000000
using namespace std;
int main(){
  int n;
  int table[Number]={0};
  for(int i=2;i<Number;i++){
    if(table[i]==0){
      for(int j=2*i;j<Number;j+=i){
	table[j]=1;
      }
    }
    table[i]=(table[i]?0:1)+table[i-1];
  }
  while(cin>>n){
    cout<<table[n]<<endl;
  }
  return 0;
}

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

int primes[1000000]={0};


int main(){
    primes[0] = -1;
    primes[1] = -1;
    for(int i=2; i<1000; i++){
        if(primes[i]==-1) continue;
        for(int j=i+1; j<1000000; j++){
            if(j%i==0) primes[j] = -1;
        }
    }
    int n;
    while(-1!=scanf("%d", &n)){
        int ans = 0;
        for(int i=2; i<=n; i++){
            if(primes[i] == 0) ans++;
        }
        cout << ans << endl;
    }
}

C++: j,a['   '],s;main(i){for(;++i<1e6||~scanf(s="%d\n",&j)&&printf(s,a[j]);)for(a[i]=s+=!a[j=i];j<1e6;a[j+=i]=1);}

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

#define MAX 1000000

int main( void )
{
	vector <bool> primes(MAX+1, false);

	for ( int i = 3; i <= MAX; i += 2 )
	{
		primes[i] = true;
	}

	for ( int i = 3; i <= MAX; i += 2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}
	primes[2] = true;
	
	int n;
	while ( cin >> n )
	{
		int cnt = 0;
		if ( n >= 2 )
			cnt++;
		for ( int i = 3; i <= n; i += 2 )
		{
			if ( primes[i] )
				cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool isprime(int& num)
{
    static int c;
    for(c=2; c <= sqrt(num)+1; c++)
        if(num % c ==0) return false;
    return true;
}

int main()
{
    int ans = 0;
    int buff;
    while(cin >> buff);
    {
        for(int d =2; d <= buff; d++)
            if(isprime(d)) ans++;
        cout << ans << " ";
        ans  = 0;
    }
    cout << endl;
    return 0;
}

C++: #include<iostream>
using namespace std;
const int N_MAX = 999999;
int main(){
    int n, cnt;
    while(cin >> n){
        bool is_prime[N_MAX] = {false};
        is_prime[1] = true;
        for(int i = 2; i*i <= n; i++){ 
            if(!is_prime[i]){
                for(int j = i; i*j <= n; j++){
                    is_prime[i*j] = true;
                }
            }
        }
        cnt = 0;
        for(int k = 1; k <= n; k++){
            if(!is_prime[k]) {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}