Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	for sc.Scan() {
		input := nextInt()
		fmt.Println(IsPrime(input))
	}
}

func IsPrime(num int) int {
	eratos := make([]bool, num+1)
	c := 0
	for i := 2; i < len(eratos); i++ {
		if eratos[i] == false {
			c++
			eratosCalc(i, eratos)
		}
	}
	return c
}

func eratosCalc(primeNum int, eratos []bool) {
	for i := primeNum * primeNum; i < len(eratos); i += primeNum {
		eratos[i] = true
	}
}

func next() string {
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

std::vector<int> PRIMES;

void init_primes(int max)
{
  if (max < 2) return;
  std::set<int> candidate;
  PRIMES.push_back(2);
  for (int i = 3; i < max; i+=2) {
    candidate.insert(i);
  }
  for (int i = 3; i < sqrt(max); i+=2) {
    std::set<int>::iterator it = candidate.find(i);
    if (it != candidate.end()) {
      PRIMES.push_back(i);
      int del_num = i;
      while (del_num < max) {
        it = candidate.find(del_num);
        if (it != candidate.end()) candidate.erase(it);
        del_num += i;
      }
    }
  }
  for (std::set<int>::iterator it = candidate.begin();
       it != candidate.end(); ++it) {
    PRIMES.push_back(*it);
  }
}

int main()
{
  const int max = 100000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
}

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

using namespace std;

int main() {
  int n;

  while(1) {
    cin >> n;
    if(cin.eof()) break;
    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(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;
	int a=0;
	cin >> n;
		for(int i = 1; i <= n; ++i){
			for(int j = 2; j <= i; ++j){

				if(i%j == 0){
				if(i==j){
					++a;
				}else{
					break;
				}
				}
		}
	
	}
		cout << a << '\n';
}

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

int main(void)
{
  bool notPrime[1000000];
  notPrime[1] = true;
  int primeNum[1000000];
  int i,j;
  for(i=2; i<1000000; ++i){
    if(!notPrime[i]){
      primeNum[i] = primeNum[i-1]+1;
      if(i<1000){
        for(j=i*2; j<1000000; j+=i){
          notPrime[j] = true;
        }
      }
    }else{
      primeNum[i] = primeNum[i-1];
    }
  }
        
  int n;
  while(scanf("%d", &n) != EOF){
    printf("%d\n", primeNum[n]);
  }

  return 0;
}

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

int main(){
  int n;
  bool prime[N];
  for(int i=0;i<N;i++) prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=0;i<N/2;i++){
    if(!prime[i]) continue;
    for(int j=i+i;j<N;j+=i) prime[j]=false;
  }
  while(cin>>n){
    int ans=0;
    for(int i=0;i<=n;i++)
      if(prime[i]) ans++;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
bool F(int n)
{
	bool r=true;
	for(int i=2;i<=(n/2);i++)
	{
		if(n%i==0){
			r=false;
			break;
		}
	
	}	
	return r;
}

int main()
{
	int number=0;
	int result=0;
	while(1)
	{
		result=0;
		cin>>number;
		for(int i=number;i>=2;i--)
		{
			if(F(i)==true)
				result++;
		}
		cout << result <<endl;
	}
	return 0;
}

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

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

#define N 1000000
int main() {
  vector<int> table(N,1);
  table[0]=table[1]=0;
  for (int i=2; i*i<N; i++)
    if (table[i])
      for (int j=i*2; j<N; j+=i)
        table[j] = 0;
  int n;
  while(cin>>n) {
    int ans=0;
    for (int i=2;i<=n;i++) {
      if (table[i]) ans++;
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000
int main( void )
{
	vector <bool> prime( MAX, false );
	prime[2] = true;
	for ( int i = 3; i * i <= MAX; i++ )
	{
		prime[i] = true;
	}

	for ( int i = 3; i <= MAX; i++ )
	{
		if ( prime[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				prime[j] = false;
			}
		}
	}

	while ( !cin.eof() )
	{
		int n;
		cin >> n;
		if ( cin.eof() )
			break;

		int cnt = 1;
		for ( int i = 3; i < n; i += 2 )
		{
			if ( prime[i] ) cnt++;
		}

		cout << cnt << endl;

	}

	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; ; ++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();
            }
            if(prime_table.back() <= sn)
            {
                break;
            }
        }
        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 <cmath>

using namespace std;
int main()
{
    bool a[1000000];
    for (int i = 0; i < 1000000; i++) {
        a[i] = true;
    }
    for (int i = 2; i <= sqrt(1000000); i++) {
        if (a[i]){
            for (int j = i; i*j < 1000000; j++) {
                a[i*j] = false;
            }
        }
    }
    
    
    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i = 2; i <= n; i++) {
            if (a[i]){
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
int a[1000000];
int sum[1000000];
int n;
int main(){
 for (int i=2;i<1000000;i++){
  if (!a[i])
   for (int j=i*2;j<1000000;j+=i)
    a[j]=1;
 }
 for (int i=2;i<1000000;i++) sum[i]=sum[i-1]+(a[i]==0?1:0);
 while (cin>>n)
  cout<<sum[n]<<endl;
 return 0;
}