Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		fmt.Println(countPrime(a))
	}
}

func countPrime(a int) int {
	primes := make([]bool, a+1)
	n := 0
	for i := 2; i <= a; i++ {
		if primes[i] == false {
			n++
			for j := i * i; j <= a; j += i {
				primes[j] = true
			}
		}
	}
	return n
}

C++: #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define N 999999L
bool num[N];

void furui(){
  long int i;
  int divide;
  int rt = (int) sqrt(N);
  for(i = 0L; i < N; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;
  for(divide = 2; divide <= rt; divide++){
    if(num[divide] == false) continue;
    for( i = divide; i < N; i+= divide){
      num[i] = false;
    }
    num[divide] = true;
  }
}

int main(void){
  int c, i, j;
  long int k;
  char buf[7];
  long int n;
  long int count;

  furui();

  for(j = 0; j < 30; j++){
    for(i = 0; ;i++){
      c = getchar();
      if(c == EOF || c == '\n'){
        buf[i] = '\0';
        break;
      }
      buf[i] = c;
    }
    n = atol(buf);
    count = 0L;
    for(k = 1L; k <= n; k++){
      if(num[k] == 1) count++;
    }
    std::cout << count << "\n";
    if(c == EOF) break;
  }
  return 0;
}

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

using namespace std;

#define maxn 999999 + 5
typedef long long ll;

int prime[maxn];

void init(){
    for(int i=2;i<maxn-4;i++)
        prime[i] = i % 2;
    prime[2]=1;
    prime[1]=0;
    for(int i=2;i*i<=maxn;i++){
        if(!prime[i])continue;
        for(int j=i;j*i<=maxn;j++)
            prime[i*j]=0;
    }
    for(int i=2;i<=maxn;i++)
        prime[i] += prime[i-1];
}
int main(){
    int n;
    init();
    
    while(~scanf("%d",&n))
        printf("%d\n",prime[n]);
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdio>

using namespace std;

bool isPrime(int x);

int main(void) {
	int n;
	while(scanf("%d", &n) != EOF) {
		
		int count = 0;
		for(int i = 1; i < n; i++) {
			if(isPrime(i))		count++;
		}
		
		cout << count << endl;
	}
	
	return 0;
}

bool isPrime(int x) {
	if(x < 2)			return false;
	else if(x == 2)		return true;
	
	if(x % 2 == 0)		return false;
	for(int i = 3; i * i <= x; i += 2) {
		if(x % i == 0)	return false;
	}
	return true;
}

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

int main(){
	int n,i,j,sqrtn,sum,flag;
	char number[1000000];
	while(scanf("%d",&n)!=EOF){
		for(i=0;i<n;i++){
			number[i]=0;
		}
		sum=0;
		for(i=3;i<=n;i+=2){
			if (number[i]==1){
				continue;
			}
			sqrtn=(int)sqrt(i);
			flag=0;
			for(j=1;j*6-1<sqrtn;j++){
				if(i%(j*6+1)==0 || i%(j*6-1)==0){
					flag=1;
					break;
				}
			}
			if(flag==0){		/*ツ素ツ青板つカツづ。ツづ按つ「ツづ個づ可フツδ可グツづーツ猟ァツづづつュツづヲ*/
				sum++;
				for(j=i;j<n;j+=i){
					number[i]=1;
				}
			}
		}
		printf("%d\n",sum);
		
	}
	return 0;
}

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

using namespace std;
int n;
int pr[170]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009};
bool prime(int x)
{
	int i;
	for(i=0;pr[i]*pr[i]<=x;i++)
	{
		if(x%pr[i]==0) 
		{
		 return false;
		}
	}
	return true; 
}

int main()
{
    while(cin>>n) {
        if(n==1) {
            printf("0\n");
            continue;
        }
        int ans=1;
        if(n==2) {
            printf("%d\n", ans);
            continue;
        }
        for(int i=3; i<=n; i+=2)
           if(prime(i)) ans++;
        printf("%d\n", ans);
    }
    return 0;
}

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

std::vector<std::size_t> prime_table = {2};

void make_prime_table(const std::size_t n)
{
    const std::size_t found_last_prime = prime_table.back();
    if(found_last_prime < n)
    {
        std::list<std::size_t> undefined_table;

        for(std::size_t i = found_last_prime + 1; i <= n; ++i)
        {
            undefined_table.push_back(i);
        }

        const std::size_t sn = std::sqrt(n);
        for(std::size_t p = 0; prime_table.back() <= sn; ++p)
        {
            for(auto u = undefined_table.begin(); u != undefined_table.end();)
            {
                if(0 == *u % prime_table[p])
                {
                    u = undefined_table.erase(u);
                }
                else
                {
                    ++u;
                }
            }
            if(undefined_table.empty())
            {
                break;
            }
            if(found_last_prime <= prime_table[p])
            {
                prime_table.push_back(undefined_table.front());
                undefined_table.pop_front();
            }
        }
        prime_table.insert(prime_table.end(), undefined_table.begin(), undefined_table.end());
    }
}

std::vector<size_t> prime_acc = {0};

std::size_t prime_size(const std::size_t limit)
{
    if(prime_acc.size() <= limit)
    {
        make_prime_table(limit);
        auto it = prime_table.begin();
        while(prime_acc.size() <= limit)
        {
            it = std::lower_bound(it, prime_table.end(), prime_acc.size());
            if(it != prime_table.end())
            {
                prime_acc.insert(prime_acc.end(), *it - prime_acc.size(), prime_acc.back());
                prime_acc.push_back(prime_acc.back() + 1);
            }
            else
            {
                prime_acc.insert(prime_acc.end(), limit - prime_acc.size() + 1, prime_acc.back());
            }
        }
    }
    return prime_acc[limit];
}

int main()
{
    std::size_t n;

    while(std::cin >> n, !std::cin.eof())
    {
        std::cout << prime_size(n) << std::endl;
    }
}

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

int main(void){
int unti[100002] = {0};
fill(unti,unti + 100002,0);
for(int n = 2;n < 100002;n++)
{
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100002;a++)
{
	unti[a * n]++;
}
}
}
int b;
while(cin >> b )
{
int cnt = (count(unti,unti+b+1,0) - 2);
cout << cnt << endl;
}
return 0;
}

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

using namespace std;

#define N 100000

int main(){

    bool primes[N];
    int  n; 

    fill(primes, primes + N, true);
    primes[0] = false;
    primes[1] = false;
    
    for(int i = 2; i < N; ++i){
        if(primes[i]){
            for(int j = i + i; j < N; j += i)primes[j] = false;
        }
    }

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

C++: #include<iostream>
using namespace std;
int main(){
	int N,count=0;
	cin >> N
	for(int x=2;x<=N;x++){
		int flag = 0;
		for(int y=2;y<x;y++){
			if((x%y)==0)	flag = 1;
		}
		if(flag == 0)	count++;
	}
	cout << count << endl;
	return 0;
}