Go: package main

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

func main() {
	b2i := func(b bool) int {
		if b {
			return 1
		}
		return 0
	}

	prime := func(n int) []int {
		ans := make([]int, n+1)
		for i := 2; i <= n; i++ {
			b := ans[i] == 0
			ans[i] = ans[i-1] + b2i(b)
			if b {
				for j := i * 2; j <= n; j += i {
					ans[j] = 1
				}
			}
		}
		return ans
	}
	reader := bufio.NewScanner(os.Stdin)
	primeT:=prime(999999)
	for reader.Scan() {
		n, _ := strconv.Atoi(reader.Text())
		fmt.Println(primeT[n])
	}
}

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

int main(){
  bool is_prime[1000000];

  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<1000000i++){
    is_prime[i] = true;
  }

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

  int n_prime[1000000];

  int cnt = 0;
  for(int i=0;i<1000000;i++){
    if(is_prime[i]){
      cnt++;
    }
    n_prime[i] = cnt;
  }

  while(true){
    int n;
    cin >> n;

    if(cin.eof())
        break;

    cout << n_prime[n] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int a,b,c=0;
	while(cin>>a){
		for (int A=2;A<=a;A++){
			for (int B=2;B<=A;B++){
				b=A%B;
				if (A==B){
					c++;
					break;
				}
				if (b==0) break;
			}
		}
		cout<<c<<endl;
		c=0;
	}
	return 0;
}

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

#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 << std::endl;
    if(c == EOF) break;
  }
  return 0;
}

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

int main(){
	int cnt=0, x, n, i, j;
	bool flg;
	double rootx;
	int rootintx;
	while(cin>>n){
		cnt=0;
		if(n>=2)cnt++;
		for(x=3;x<=n;x++){
			flg = true;
			if(x==2){
				cnt++;
				continue;
			}
			if(x<2 || !(x%2)){
				continue;
			}
			rootx = sqrt(x);
			rootx = ceil(rootx);
			rootintx = int(rootx);
			for(j=2;j<=rootintx;j++){
				if(!(x%j)){
					flg=false;
					break;
				}
			}
			if(flg)cnt++;
		}
		cout<<cnt<<endl;;
	}
	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <time.h>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>

#define out freopen("output.txt", "w", stdout);
#define in freopen("input.txt", "r", stdin);
#define clr(arr, key) memset(arr, key, sizeof arr)
#define pub push_back
#define pob pop_back
#define infinity 2147483647
#define LL long long
#define Pi acos(-1)
#define SZ 1000010

///int col[8] = {0, 1, 1, 1, 0, -1, -1, -1};
///int row[8] = {1, 1, 0, -1, -1, -1, 0, 1};
///int col[4] = {1, 0, -1, 0};
///int row[4] = {0, 1, 0, -1};

using namespace std;
bool primes[1100000];
int sieve(int n)
{
    int i, j;
    primes[1] = 1;
    for(i = 4; i <= 1100000; i += 2)
        primes[i] = 1;
    for(i = 3; i < 1100000 / i; i += 2)
    {
        if(primes[i] != 1)
        {
            for(j = 2; j * i < 1100000; j++)
                primes[i * j] = 1;
        }
    }
    int cnt = 0;
    for(i = 2; i <= n; i++)
        cnt += !primes[i];
    return cnt;
}

int main()
{
    int n;
    cin >> n;
    cout << sieve(n) << endl;
    return 0;
}

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

int prime(int num){

	if(num<2){
		return 0;
	}else if(num==2){
		return 1;
	}else if(num%2==0){
		return 0;
	}
	
	for(int s=3; pow(s,2)<=num; s+=2){
		if(num%s==0){
			return 0;
		}
	}
	
	return 1;
}

int main(){
	int num, count=0;
	
	cin >> num;
	
	for(int i=0; i<=num; i++){
		if(prime(i)==1){
			count++;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

C++: #include<cstdio>
using namespace std;
const int MAX = 1200000;
bool prime[MAX];
int solve(int n){
  int cnt = 1;
  if(n == 1)
    return 0;
  else if(n == 2)
    return 1;
  else{
    for(int i = 3 ; i <= n ; i++){
      if(prime[i])
        cnt++;
    }
  }
  return cnt;
}
int main(){
  for(int i = 0 ; i < MAX ; i++)
    prime[i] = true;
  prime[0] = prime[1] = false;
  for(int i = 4 ; i < MAX ; i += 2)
    prime[i] = false;
  for(int i = 3 ; i < MAX ; i += 2){
    if(prime[i]){
      for(int j = i * 2 ; j < MAX ; j += i)
        prime[j] = false;
    }
  }
  int n;
  while(scanf("%d",&n) != EOF){
    printf("%d\n",solve(n));
  }
}

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

class PrimeNumbers
{
public:
	vector<int> primeNumbers;

	PrimeNumbers()
	{
		this->createPrimeNumbers();
	}
	
	int answer(int N)
	{
		int result = 0;
		for(auto it = this->primeNumbers.begin(); it != this->primeNumbers.end(); it++)
		{
			if(*it <= N)result++;
			else break;
		}
		return result;
	}

	bool checkOf(int n)
	{
		if(n % 2 == 0)return false;

		bool prime = false;
		for(auto it = this->primeNumbers.begin(); it != this->primeNumbers.end(); it++)
		{
			if(n == *it)
			{
				prime = true;
				break;
			}
		}
		return prime;
	}

	void createPrimeNumbers()
	{
		int max_number = 999999+1;
		this->primeNumbers = vector<int>();
		this->primeNumbers.push_back( 2 );
		for(int i = 3; i < max_number; i += 2)
		{
			bool prime = true;
			for(auto it = this->primeNumbers.begin(); it != this->primeNumbers.end(); it++)
			{
				if(i % *it == 0)
				{
					prime = false;
					break;
				}
			}
			if(prime)
			{
				this->primeNumbers.push_back(i);
			}
		}
	}

};

int main()
{
	int N;
	PrimeNumbers pn = PrimeNumbers();
	while(cin >> N)
	{
		cout << pn.answer(N) << endl;
	}
	return 0;
}

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

int main(){
int unti[100001] = {0};
fill(unti,unti + 100001,0);
for(int n = 2;n < 100000;n++){
if(unti[n] == 0)
{
for(int a = 2;(a * n) < 100000;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>
using namespace std;
 
__forceinline int isPrime(int n){
	//sieve of Eratosthenes
	if(n==2) return 1;
	if(n%2==0 || n<2){
		return 0;
	}

	for(int i=3; i*i<=n; i+=2){
		if(n%i==0){
			return 0;
		}
	}
	return 1;

}

//0009
int main()
{
	int n;
 
	while(cin >> n){
		int cnt = 0;
		for(; n>1; n--){
			if(isPrime(n))
				++cnt;
		}
		cout << cnt << endl;
	}
  return 0;
}