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] = 1
        }
        primes[0] = 0
        primes[1] = 0
        Soe()
}

func Soe() {
        for i := 2; i < MAX; i++ {
                if primes[i] > 0 {
                        for j := i*2; j < MAX; j+=i {
                                primes[j] = 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;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

vector<lint> primearray(lint N) {
	//N以下の素数を列挙
	vector<lint> R;
	vector<bool> prime;
	for (int i = 0; i <= N; i++) {
		prime.push_back(true);
	}
	if (N < 2) {
		return R;
	}
	prime[0] = false;
	prime[1] = false;
	for (lint i = 2; i * i <= N; i++) {
		if (!prime[i])continue;
		for (int j = 2 * i; j <= N; j += i) {
			prime[j] = false;
		}
	}
	for (lint i = 0; i < prime.size(); i++) {
		if (prime[i]) {
			R.push_back(i);
		}
	}
	return R;
}

int main() {
	lint N;
	while (cin >> N) {
		cout << primearray(N).size() << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

bool a[1000000];

int main()
{
    memset(a, true, sizeof(a));

    for (int i = 2; i*i < 1000000; i++) {
        if (!a[i]) continue;
        for (int j = i*2; j < 1000000; j += i) a[j] = false;
    }

    int n;
    while (~scanf("%d", &n)) {
        int cnt = 0;
        for (int i = 2; i <= n; ++i) cnt += a[i];
        printf("%d\n", cnt);
    }
}

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

using namespace std;

int main() {
  int n;

  while(!cin.eof()) {
    cin >> n;

    int m = (int)sqrt(n);
    
    vector<bool> h(n+1, true);
    h[0] = false;
    h[1] = false;

    for(int i = 2; i <= m; i++) {
      if(h.at(i)) {
	for(unsigned int s = 2; s*i < h.size(); s++) {
	  if(h.at(s*i))
	    h[s*i] = false;
	}
      }
    }
    
    int ans=0;
    for(auto f : h) {
      if(f)
	ans++;
    }

    cout << ans << endl;
  }
  return 0;
}

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

int main() {
	int n, count;
	bool *data;

	while (cin >> n) {
		data = new bool[n + 1];
		count = 0;
		data[0] = data[1] = false;
		for (int i = 2;i <= n;i++) {
			if (data[i]) {
				count++;
				for (int j = i + i;j <= n;j += i) {
					data[j] = false;
				}
			}
		}
		cout << count << endl;
		delete[] data;
	}
	return 0;
}