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>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef vector<int> VI;
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )

template<typename T>
T getPrimeNum(vector<bool> primes, T index) {
    T ret = 0;
    for (auto i = 0; i <= index; i++) {
        if (primes.at(i)) {
            ++ret;
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<bool> primes(1000000, true);
    primes[0] = false;
    primes[1] = false;
    for (unsigned long n = 2; n < 1000000; n++) {
        if (n*n > 1000000)    break;
        if (!n)    continue;
        for(unsigned long i = n+n; i < 1000000; i=i+n) {
            primes[i] = false;
        }
    }

    unsigned long input;
    vector<unsigned long> inputs;
    while (cin >> input) {
        inputs.push_back(input);
    }

    for (auto n : inputs) {
        cout << getPrimeNum(primes, n) << endl;
    }

    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool memo[1000002];

int main() {

  rep (i, 1000002) memo[i] = true;

  memo[0] = memo[1] = false;

  for (int k = 2; k < 1000002; ++k) {
    if (!memo[k]) continue;
    for (int i = k+k; i < 1000002; i += k) memo[i] = false;
  }

  for (int n; cin >> n, cin; ) {
    int ans = 0;
    rep (k, n+1) if (memo[k]) ++ans;
    cout << ans << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a,b,c,i,j;
    while(scanf("%d",&a)!=EOF){
        b=0;
        for(i=2;i<=a;i++){
            c=0;
            for(j=2;j*j<=i;j++){
                if(i%j==0){c++;break;}
            }
            if(i==2||i==3)c++;
            if(c==0)b++;
            if(i==2||i==3)b++;
        }
        cout<<b<<endl;
    }
    return 0;
}

C++: #include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

const int N = 100000;

int main(void)
{
    bool a[N];
    int prime[N], n, count = 0;
    rep(i,N)
        a[i] = true;
    a[0] = a[1] = false;
    for(int i=2;i*i<=N;i++)
    {
        if(a[i])
        {
            prime[i] = prime[i-1] + 1;
            for(int j=i*i;j<N;j+=i)
                a[j] = false;
        }
        else
            prime[i] = prime[i-1];
    }

    while(cin >> n)
    {
        rep(i,n)
        {
            if(a[i] == true)
                count++;
        }
        cout << count << endl;
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
#include<vector>
#include<list>
#include<set>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

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


int main(){
    bool b[1000000]={0};
    for (int i=0;i<1000000;i++) {
        b[i]=pr(i);
    }
    int n;
    b[0]=0,b[1]=0;
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for (int i=1;i<=n;i++){
            if (b[i]==true) ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int get_numprime( int num );
bool prime( int n );


int main(void)
{
	int num;

	while(1)
	{
		cin >> num;
		if( cin.eof() ) break;
		cout << get_numprime( num ) << endl;
	}

	return 0;
}

int get_numprime( int num )
{
	int numprime = 1; // 2はすでにカウント

	for( int i = 3 ; i <= num ; i+=2 )
	{
		if( prime(i) ) numprime++;
	}

	return numprime;
}

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

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

int count(int n);

int main(void){
	while (true){
		int n; cin >> n;
		if (!n){
			break;
		}
		cout << count(n) << endl;
	}
	return 0;
}

int count(int n){
	int ct = 0;
	bool *prime = new bool[n];
	//bool prime[999999];
	for (int i = 0; i <= n;i++){
		prime[i] = 0;
	}
	prime[2] = 1;
	for (int i = 3; i <= n; i = i + 2){
		prime[i] = 1;
	}
	for (int i = 3; i <= sqrt(n * 1.0); i = i + 2){
		if (prime[i] == 0) continue;
		for (int j = i * 2; j <= n; j = j + i){
			prime[j] = 0;
		}
	}
	for (int i = 3; i <= n; i = i + 2){
		if (prime[i] == 1) ct++;
	}
	ct++; //2を数えていない分
	return ct;
	delete[] prime;
}

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

#define MAX 1000000

using namespace std;

int main() {
	bool prime[MAX];
	fill(prime, prime + MAX, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i < MAX; i++) {
		for (int j = 2; i * j < MAX; j++) {
			if (!prime[i * j]) {
				continue;
			}
			prime[i * j] = false;
		}
	}

	int n, count;
	while (cin >> n) {
		count = 0;
		for (int i = 2; i <= n; i++) {
			if (prime[i]) {
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(int argc, char *argv[]){
	int n;
	while(cin>>n){
		bool check[999999]={false};
		int count=0;
		for(int i=2;i<=n;i++){
			if(!check[i]){
				for (int j = 1; i*j <= n;j++){
					check[i*j]=true;
				}
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    int j,s[1000000]=0;
    long i,n,d=0;
    
    for(i=3;i<1000000;i++){
        for(j=2;j*j<i;j+=2){
            if(j%i==0){
                d--;
                break;
            }
            if(j==2)
                j=1;
        }
        s[i] = ++d;
    }
    
    while(EOF != scanf("%d",&n)){
        printf("%d\n",&d);
    }
    
    
    return 0;
}