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>

#define rep(i,n)      for(int i=0;i<n;i++)

using namespace std;

static const int LIM = 1000000;
bool np[LIM / 2];

bool is_prime(int n)
{
	return n == 2 || (n % 2 == 1 && !np[n/2]);
}

int main()
{
	np[0] = true;
	for (int i = 3; i * i < LIM; i += 2)
		if (!np[i/2])
			for (int j = 3 * i; j < LIM; j += 2 * i) np[j/2] = true;

	int N;
	while (cin>>N)
	{
		int c = 0;
		rep(i,N+1)
			if (is_prime(i)) c++;
		cout << c << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
int main(){
	int i,j,n;
	static bool prime[1000001];
	for (i = 3; i <= 1000000; i += 2){
		prime[i] = true;
	}
	prime[2] = true;

	for (i = 3; i <= 1000; i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 1000000 / i; j += 2){
				prime[i * j] = false;
			}
		}
	}
	while(cin >> n && n){
		int count = 0;
		for(i=2;i<=n;i++){
			if(prime[i] == true) count++;
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<math.h>
bool b(int n){
if (n < 2)  
        return false;  
    //偶数一定不是素数，去掉偶数  
    if (n == 2)  
        return true;   
    //从3?始,判断指定数的平方根内的数  
    for (int i = 3; i <= sqrt(n); i++) {  
        if (n % i == 0)  
            return false;  
    }  
    return true; 
}
int main(){
int n,c,i;
while(std::cin>>n){
c=0;
if(n==2)c=1;
for(i=3;i<=n;i+=2){
if(b(i))c++;
}
std::cout<<c<<"\n";
}

return 0;
}

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

int main(){
  bool is_prime[1000000];
  for(int i=0;i<1000000;i++){
    is_prime[i] = true;
  }
  is_prime[0] = false;
  is_prime[1] = false;
  
  for(int i=2;i<1000000;i++){
    if(is_prime[i]){
      for(int j=2*i;j<1000000;j += i){
	is_prime[j] = false;
      }
    }
  }
 
 int n,counter;
 cin >> n;
 counter = 0;
 
 for (int k = 1; k <= n; k++)
   if(is_prime[k]){
     counter++;
   }

 cout << counter << endl;
 
 return 0;
}

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

const int INF = 1000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int prime[INF];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;

  REP(i, INF) prime[i] = 1;

  prime[0] = prime[1] = 0;

  for (int i =  2; i * i <= INF; i++){
    if (prime[i]){
      for (int j = 2; i * j <= INF; j++){
        prime[i * j] = 0;
      }
    }
  }

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

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

int main(){
 int i,j,n,count,flg;
 scanf("%d",&n);
 if(1!=n){
  for(i=2,count=0;i<=n;i++){
   for(j=2,flg=1;j<=sqrt(i);j++)
    if(i%j==0){  flg=0; break; }
   count+=flg;
  }
 }else{ count=1; }
 printf("%d\n",count);
 return 0;
}

C++: #include <cstdio>
const int N = 1000000;
int p[NUM],int pN[NUM];
main(){p[0]=0;p[1]=0;int i,k,n,c;
for(i=2;i<N;i++)prime[i]=1;for(i=2;i*i<N;){for(k=2;i*k<N;k++)p[i*k]=0;do{i++;}while(!p[i]);}for(i=0,c=0;i<N;i++){p[i]&&c++;pN[i] = c;}for(;scanf("%d",&n)+1;printf("%d\n",pN[n]));}

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

int main() {
	int n, ans; bool not_prime[1000000 + 1];
	for (int i = 2; i <= sqrt(1000000); i++) {
		if (!not_prime[i]) {
			for (int j = i * 2; j <= 1000000; j += i) {
				not_prime[j] = true;
			}
		}
	}
	while (cin >> n) {
		ans = 0;
		for (int i = 2; i <= n; i++) {
			if (!not_prime[i]) { ans++; }
		}
		cout << ans << endl;
	}
	return 0;
}

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

map<int,bool>memo;

bool isprime(int q){
	map<int,bool>::iterator it;
	bool ret=true;
	if(q==2){
	}else if(q%2==0){
		ret=false;
	}else{
		it=memo.find(q);
		if(it!=memo.end()){
			return (*it).second;
		}else{
			int max=sqrt(q);
			for(int i=3;i<q;i=i+2){
				if(q%i==0)ret=false;
				break;
			}
		}
	}
	memo.insert(pair<int,bool>(q,ret));
	return ret;
}

int main(){
	int n;
	while(cin>>n){
		int sum=0;
		for(int i=2;i<=n;i++){
			if(isprime(i))sum++;
		}
		cout<<sum<<endl;
	}
	return 0;
}

C++: #include<stdio.h>

bool p(int a){
	if(a==2)return true;
	if(a<2||a%2==0)return false;
	for(int i=3;i*i<=a;i+=2){
		if(a%i==0)return false;
	}
	return true;
}

int main(void){
	int n,cnt;
	while(scanf("%d",&n)!=EOF){
		cnt=0;
		for(int i=2;i<=n;i++){
			cnt+=p(i);
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

int main()
{
	int n=0;
	int a[40]={0};
	while(cin>>a[n++]);n--;
	for(int i=0;i<n;i++)
	{
		if(a[i]==2)cout<<"1"<<endl;
		else if(a[i]==3)cout<<"2"<<endl;
		else
		{
			int pcnt=0,cnt=0;
			for(int j=2;j<=a[i];j++)
			{
				for(int k=1;k<=j;k++)
				{
					if(j%k==0)cnt++;
				}
				if(cnt==2)pcnt++;cnt=0;
			}
			cout<<pcnt<<endl;pcnt=0;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
bool f[1000005];
int tot[1000003];
int main()
{
    memset(f,true,sizeof(f));
    for(int i=2;i<=1000;i++)
    {
        if (f[i])
        {      
            for(int j=i+i;j<=1000000;j=j+i)
            {
                f[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++)
    {
        if(f[i])
        {
            tot[i]=tot[i-1]+1;
        }
        else tot[i]=tot[i-1];
    }
    int in;
    while(cin>>in) cout<<tot[in]<<endl;
}

C++: #include<stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i <= n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int sum[1000];
	int i, n;
	sum[0]=0;
	while(scanf("%d",&n) != EOF){
		for(i=2;i<=n;i++){
			if(isprime(i)){
				sum[i+1]=sum[i]+1;
			}else{
				sum[i+1]=sum[i];
			}
		}
		printf("%d\n",sum[n+1]);
	}
	return 0;
}

C++: #include <iostream>

int main() {
	int n;

	/**
	 * 0: No data
	 * 1: Prime number
	 * 2: Non prime number
	 */
	int db[999999] = {2, 2, 1, 1};

	while (std::cin >> n) {
		int primes = 0; // n以下の素数の数
		int now;

		/* dbを走査 */
		loop:
		for (int i = 0; i <= n; i++)
		switch (db[i]) {
			case 1:
				primes++;
				break;
			case 0:
				now = i;
				goto next_phase;
		}

next_phase:
	/* 足りてなければ必要なだけごにょごにょ */
		for (int j = now; j <= n; j++) {
			bool flag = false; // はずれの目印
			for (int k = 2; k < j; k++)
				if (!(j % k)) {
					flag = true;
					break;
				}
			if (!flag) {
				db[j] = 1;
				primes++;
			} else
				db[j] = 2;
		}
		std::cout << primes << std::endl;
	}
}

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

const int maxn = 1e6 + 10;
typedef long long LL;

int p[maxn];
bool l[maxn];

int prime() {
    int cnt = 0;
    for(int i = 2; i < maxn; ++i) {
        if(!l[i]) {
            p[cnt++] = i;
            LL con = i;
            LL j;
            while((j = i * (con++)) < maxn) {
                l[j] = true;
            }
        }
    }
    return cnt;
}

int main() {
    int cnt = prime();
    int n;
    while(scanf("%d", &n) != EOF) {
        int ans = upper_bound(p, p + cnt, n) - p;
        printf("%d\n", ans);
    }
    return 0;
}