Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include <iostream>
using namespace std;
 
 
int main()
{
    int max = 10000;
    int prime[max];
    
    fill(prime, prime + max, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < max; i++) {
        if (prime[i]) {
            for (int j = 2*i; j < max; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for(int i = 1;i < max; i++){
	    prime[i] = prime[i] + prime[i-1];
    }
    
    int aaa;
    while (cin >> aaa) {
	cout << prime[aaa] << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int pr[50847534];
int x = 0;

int nextpr(int p){
  int nxp = p+2;
  int i;
  int ok;
  x++;
  if(p==2)return 3;
  while(1){
      /*printf("p=%d->",nxp);*/
    for(i=0;pr[i]*pr[i]<=nxp;i++){
      ok = 1;
      if(!(nxp%pr[i])){
        ok = 0;
        break;
      }
    }
    if(ok){
        /*printf("O\n");*/
      return nxp;
    }else{
        /*printf("X\n");*/
      nxp+=2;
    }
  }
}

int main(){
    int n;
    int i;
    pr[0] = 2;
    while(scanf("%d",&n)!=EOF){
        printf("n=%d\n",n);
        i=0;
        if(n-1){
            while(pr[i]<=n){
                /*printf("prime:%d(%d)\n",pr[i],i+1);*/
                i++;
                if(i>=x){
                    pr[i] = nextpr(pr[i-1]);
                }
            }
        }
        printf("%d\n",i);
    }
}

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

const int INF = 1 << 30;
const int MAX_PRIME = 1000010;
bool is_prime[MAX_PRIME + 10];
vector<int> primes;

void init_primes() {
    fill(is_prime, is_prime + MAX_PRIME + 10, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=0; i<=MAX_PRIME; i++) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int k=i+i; k<=MAX_PRIME; k+=i) {
                is_prime[k] = false;
            }
        }
    }
}

int main() {
    init_primes();
    primes.push_back(INF);

    int N;
    while(scanf("%d", &N) != EOF) {
        printf("%zu\n", upper_bound(primes.begin(), primes.end(), N) - primes.begin());
    }
    return 0;
}

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

int prime[MAX];


int main(){
	prime[0]=1;
	prime[1]=1;
	prime[2]=0;
	prime[3]=0;
	for(int i=0;i*i<=MAX;i++) {
		if(prime[i]==1) continue;

		for(int t = i*2;t<MAX;t+=i)
			prime[i]=1;
	}

	while(cin.eof()){
		int m = 0;
		cin >> N;
		for(int i =0;i<=N;i++)
			if(prime[i]==0)
				m++;

		cout << m << endl;
	}

	return 0;
}

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

void pr( int [],int);
int main()
{   int n;  int counter; int *p;  int x=1;
const  int  m=100000;
 p=new int[1000000];
  pr(p,m);
	while(x<=30)
	{ counter=0;
	cin>>n;
	if(n<=999999)
	{
		for( int i=2; i<=n; i++)
		{
			if(*(p+i))
				counter++;
		}
		cout<<counter<<endl;
	}
	x++;
	}
	delete p;
}

void pr( int p[],int d )
{  
	*(p+0)=0; *(p+1)=0; bool flag;
	
	for(int i=2; i<d; i++)
	{
		flag=true;
		for(int j=2; j<i; j++)
		{
			if(i%j == 0)
			{
				flag=false;
				break;
			}
		}
		if(flag==true)
			*(p+i)=1;
		else
			*(p+i)=0;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;

#define MAX (1000000)
int main(){
  vector<bool> isP(MAX,true);
  vector<int>  ans(MAX,0);
  int n;
  isP[0] = isP[1] = false;
  for(int i=2; i*i<MAX; i++)
    if(isP[i]){
      ans[i] = ans[i-1] + 1; 
      for(int j=i+i; j<MAX; j+=i)
	isP[j] = false;
    }else{
      ans[i] = ans[i-1];
    }
  
  while(cin>>n) cout<<ans[n]<<endl;
  return 0;
}

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

int main(){
	long long n=0,i,g,count=0;
	bool p=false;
	while(scanf("%d",&n)==1){
	for(g=2;g<=n;g++){
		for(i=2;i<g;i++){
			if(g%i==0){
				p=true;
				break;
			}
		}
		if(p) p=false;
		else{
			count++;
			p=false;
			}
		}
	printf("%d\n",count);
	count=0;
	}
	return 0;
}

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

int main()
{
	
	long int k,p[100000];
	float n;
	p[0]=2;
	while(cin>>n){
	k=0;
	int r=(int)sqrt(n);
	for(int i=3;i<=r;i++){
		for(int j=0;j<k+1;j++){
			if(i%p[j]==0){
				break;
			}else if(j==k){
				k++;
				p[k]=i;
			}
		}
	}
	int r_k=k;
	for(;r<n;r++){
		for(int i=0;i<=r_k;i++){
			if(r%p[i]==0){
				break;
			}else if(i==r_k){
				k++;
			}
		}
	}
	if(k!=0&&k!=1){
	cout<<k+1<<endl;
	}else{
		cout<<k<<endl;
	}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include<algorithm>
#define pf printf
#define sf scanf

using namespace std;

bool isprime(int n){
	if(n < 2)return false;
	for(int i=2;i*i<=n;i++)
		if( n%i == 0)return false;
	return true;
}

int main()
{
    int n;
	bool arr[1000000] = {false};
	for(int i=0;i<1000000;i++){
		arr[i] = isprime(i);
	}
	while(cin >> n){
		int coun=0;
		for(int i=0;i<=n;i++){
			if(arr[i]==true)coun++;
		}
		printf("%d\n",coun);
	}
    return 0;
}

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

using namespace std;

#define MAX 1000000

int p[MAX];

void fanc(void){
	int num = 0;
	for(int ix = 2;ix < MAX;++ix){
		if(p[ix] == 0){
			p[ix] = ++num;
			for(int jx = 2;jx*ix<MAX;++jx)
				p[jx*ix] = -1;
		}else
			p[ix] = num;
	}
}

int main()
{
	int n;
	fanc();
	while(cin >> n)
		cout <<p[n]<<endl;

	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int count;
	while (1)
	{
		cin >> n;
		if (cin.fail()) break;

		bool *isPrime;
		isPrime = new bool[n + 1];
		memset(isPrime, true, sizeof(bool) * (n + 1));
		isPrime[0] = isPrime[1] = false;
		
		count = 0;
		for (int i = 2; i <= n;++i)
		{
			while (isPrime[i] != true)
			{
				++i;
				if (i > n) break;
			}

			for (int j = i + i; j <= n; j += i)
			{
				isPrime[j] = false;
			}
		}
		for (int i = 0; i <= n; ++i)
		{
			if (isPrime[i] == true)
				++count;
		}
		cout << count << endl;
		delete[] isPrime;
	}
	return 0;
}

C++: #include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
const int Max=10000000;
bool prime[Max];
int main(void){
    int in;
    for(int i=0;i<Max;i++)prime[i]=true;
    prime[1]=false;
    for(int i=2;i<Max;i++){
        if(prime[i]){
            for(int s=i*2;s<=Max;s+=i)prime[s]=false;
        }
    }
    while(cin>>in){
        int cnt=0;
        for(int i=1;i<=in;i++){
            if(prime[i])cnt++;
        }
        cout << cnt << "\n";
    }
    return 0;
}

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