Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

func main() {
    var limit = 1000000
    var root = 1000
    var isPrime [1000000]bool
    for i := 0; i < limit; i++ {
        isPrime[i] = true
    }
    isPrime[0] = false
    isPrime[1] = false
    for i := 2; i <= root; i++ {
        if isPrime[i] {
            for j := i * i;j < limit; j+=i {
                isPrime[j] = false
            }
        }
    }
    var primeCnt [1000000]int
    var cnt = 0
    for i := 0; i < limit; i++ {
        if isPrime[i] {
            cnt++
        }
        primeCnt[i] = cnt
    }

    var sc = bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Println(primeCnt[n])
    }
}

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

int CountPrime(int n){
	
	if ((n == 0) || (n == 1)){
		return 0;
	}else{
		std::vector<bool> data(n - 1, 1);
		int count = 0;

		for (int i = 2; i <= n; i++){
			if (data[i - 2] == 1){
				for (int j = i * 2; j <= n; j += i){
					data[j - 2] = 0;
				}
			}
		}
		for (int i = 0; i < n - 1; i++){
			if (data[i] == 1){
				count++;
			}
		}

		return count;

	}
}


int main(){
	int n;

	while (std::cin >> n){
		std::cout << CountPrime(n) << "\n";
	}

	return 0;
}

C++: #include<stdio.h>

int main()
{
	int n,m;
	while(scanf("%d",&n) !=EOF)
	{
		m=0;
		for(int x=2;x<=n;x++)
		{
			for(int y=x-1;y;y--)
			{
				if(y==1)
				{
					m++;
				}
				else if(x%y==0)
				{
					break;
				}				
			}
		}
		printf("%d\n",m);
	}
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <iterator>

#include <cmath>

int main(void){
	using namespace std;

	map<int,int> input_dic;
	list<int> input;
	int k;

	while(cin >> k){
		input.push_back(k);
		input_dic[k] = 0;
	}

	int k_max = ( input_dic.rbegin() )->first;
	vector<bool> sieve(k_max, false);

	int sq_k_max = sqrt(k_max);
	for (int x=1; x<=sq_k_max; ++x) {
		for (int y=1; y<=sq_k_max; ++y) {
			int n = 4*x*x + y*y;
			if ( n<=k_max && (n%12==1 || n%12==5) ){
				sieve[n] = !sieve[n];
			}
			n = 3*x*x + y*y;
			if ( n<=k_max && n%12==7 ){
				sieve[n] = !sieve[n];
			}
			n = 3*x*x - y*y;
			if ( x>y && n<=k_max && n%12==11 ){
				sieve[n] = !sieve[n];
			}
		}
	}
	for (int n=5; n<=sq_k_max; ++n){
		if (sieve[n]){
			for (int k=n*n; k<=k_max; k+=n*n){
				sieve[k] = false;
			}
		}
	}
	sieve[2] = sieve[3] = true;

	int primeCount = 0;
	auto sieveItr = sieve.begin();
	for( auto itr=input_dic.begin(); itr!=input_dic.end(); itr++){
		for( ; distance(sieve.begin(),sieveItr) <= itr->first; sieveItr++){
			if( *sieveItr ){
				primeCount++;
			}
		}
		itr->second = primeCount;
	}

	for(auto itr=input.begin(); itr!=input.end(); itr++){
		cout << input_dic[*itr] << endl;
	}

}

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

#define INF 999999
using namespace std;

int main()
{
	int n;
	
	while (cin >> n)
	{
		int ans = 0,rootn;

		int a[INF] = {0};
		
		rootn = sqrt(n)+1;
	
		for (int i = 2; i <= rootn; i++)
		{
			if (a[i]==0)
			{
				for (int j = i+1; j <= INF; j++)
				{
					if (a[j] == 0 && j%i == 0)
					{
						a[j] = 1;
					}
				}
			}
		}
		cout << "a" << endl;
		for (int i = 2; i <= n; i++)
		{
			if (a[i]==0)
				++ans;
		}
		cout << ans << endl;
	}
			
	return 0;
}

C++: #include<stdio.h> int prime[1000000]; int main(){ prime[0]=-1; prime[1]=-1; for(int i=2;i<1000000;i++){ if(prime[i]==0){ prime[i]=1; for(int j=i*2;j<1000000;j+=i)prime[j]=-1; } } int now; while(~scanf("%d",&now)){ int ans=0; for(int i=1;i<now+1;i++)if(prime[i]==1)ans++; printf("%d\n",ans); } }

C++: /*
P135
AOJ 0009 Prime Number
Difficult: 2
*/

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <functional>
#include <string.h>
#include <cmath>

using namespace std;

const int MAXN = 999999;
int prime[MAXN + 1], pn;
int mindiv[MAXN + 1];

void GetPrime(int n)
{   //determin each num (that <= n) is prime or not.
    //and get primes into an array with pn elements
    //mindiv[i] == i means it is a prime
    fill(mindiv, mindiv+n+1, 0);
    pn = 0;
    for(int i=2; i<=n; ++i){
        if(mindiv[i] == 0) mindiv[i] = i, prime[pn++] = i;
        for(int p=0; p<pn && i*(long long)prime[p] <= n; ++p){
            mindiv[prime[p]*i] = prime[p];
            if(prime[p] == mindiv[i]) break;
        }
    }
}


int main()
{
    GetPrime(MAXN);
    int n;
    while(scanf("%d", &n) !=EOF){
        int x = upper_bound(prime, prime + pn, n) - prime;
        printf("%d\n", x);
    }

}

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 n;
  while(cin>>n){
    cout<<p[n]<<endl;
  }
  return 0;
}

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

using namespace std;
bool IsPrime[1000000];
vector<int> Prime;

void calc()
{
	for(int i = 0; i < 1000000; ++i)
	{
		IsPrime[i] = true;
	}
	for(int i = 2; i < 1000000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 1000000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	calc();
	int n;
	while(cin >> n)
	{
		int count = 0;
		int a = Prime.size() - 1;
		while(Prime[count] <= n)
		{
			if(count >= a)
			{
				break;
			}
			count++;
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1000000+10;
const int maxn=100000+5;
int prime[maxn];
bool p[MAXN];
int cnt=0;
void getPrime()
{
    memset(p,true,sizeof(p));
    p[0]=p[1]=false;
    for(int i=2;i<=MAXN;i++)
       if(p[i]) {
       	prime[cnt++]=i;
       	for(int j=i*i;j<=MAXN;j+=i)
       	    p[j]=false;
	   }
}
int main()
{
	getPrime();
	/*int k=lower_bound(prime,prime+cnt,999999)-prime;
	for(int i=k;i>=0;i--)
	   if(prime[i]<999999) {
	   	printf("%d\n",i+1);
	   	break;
	   }*/
	for(int i=0;i<cnt;i++)
	   cout<<prime[i]<<" ";
	int n;
	while(scanf("%d",&n)==1){
		int k=lower_bound(prime,prime+cnt,n)-prime;
		if(prime[k]==n) k++;
		printf("%d\n",k);
	}
	return 0;
}

C++: #include <cstdio>

int main(){
	int n;
	bool c[1000000]={true};
	int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = i;i*j < 1000000;j++){
			c[i*j-1] = true;
		}
	}
	for(int i = 1;i < 1000000;i++){
		if(c[i])t[i]=t[i-1];
		else t[i] = t[i-1]+1;
	}
	while(scanf("%d", &n)){
		printf("%d\n", t[n-1]);
	}
	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=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		if(p(i)){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

C++: #include <iostream>
#include <list>
#include <algorithm>
 
using namespace std;
 
int main() {
int n;
 
while(!cin.eof()) {
cin >> n;
list<int> search_list(n);
list<int> prime_number;
while(n!=1) {
search_list.push_front(n);
n--;
}
while(!search_list.empty()) {
int m = search_list.front();
prime_number.push_back(m);
search_list.pop_front();
list<int>::iterator it = search_list.begin();
while(it!=search_list.end()) {
if((*it % prime_number.front()) == 0){
it = search_list.erase(it);
continue;
}
it++;
}	
}
cout << prime_number.size()-1 << endl;
}
}