Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := make([]bool, 1000000)

	for sc.Scan() {
		var nmpr int

		n, _ := strconv.Atoi(sc.Text())

		lmt := int(math.Sqrt(float64(n)))

		for i := 2; i <= lmt; i++ {
			for j := 2; i*j <= n; j++ {
				if !num[i*j] {
					num[i*j] = true
				}
			}
		}

		for t := 2; t <= n; t++ {
			if !num[t] {
				nmpr++
			}
		}

		fmt.Println(nmpr)
	}

}

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

using namespace std;


int main() {
	int n;
	bool p[1000000];

	p[0] = 0;
	p[1] = 0;

	for(int i = 2; i <= 999999; i++) {
		p[i] = true;
	}

	for(int i = 2; i * i <= 999999; i++) {
		for(int j = 2; j * i <= 999999; j++) {
			p[j * i] = false;
		}
	}

	while(cin >> n) {
		int count = 0;
		for(int i = 2; i <= n; i++) {
			if(p[i] == true) {
				count++;
			}
		}

		cout << count << endl;
	}
}

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 = 1000000;
  init_primes(max);
  int i;
  while (std::cin >> i) {
    std::vector<int>::iterator it = PRIMES.begin();
    int n = 0;
    while (*it <= i && it != PRIMES.end()) {
      n++;
      it++;
    }
    std::cout << n << std::endl;
  }
  return 0;
}

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

bool isPrime(int x) {
  if (x == 2) return true;

  else if (x < 2 || x % 2 == 0) return false;

  int i = 3;
  while(i <= sqrt(x)) {
	if(x % i == 0) return false;
	i += 2;
  }
  return true;
}

int main() {
  int n;
  while(cin >> n) {
	int cnt = 0;
	for(int j = 2; j <= n; ++j) {
	  if(isPrime(j)) cnt ++;
	}
	cout << cnt << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long i64;


template<i64 N> struct prime_numbers{
  set<i64> primes;
  bool p[N+1];
  
  constexpr prime_numbers<N>() : primes(), p() {
    p[0] = p[1] = true;
    for(i64 i=2; i<=N; i++) {
      if(p[i]) continue;
      if(i*i<=N) {
        for(i64 j=i; i*j<=N; j++) {
          p[i*j] = true;
        }
      }
      primes.insert(i);
    }
  }
  
  bool is_prime(i64 n) {
    return primes.find(n) != primes.end();
  }
};


int main(){
  i64 n;
  prime_numbers<1000000LL> ps;
  while(cin >> n) {
    int res = 0;
    for(int i=1; i<=n; i++) if(ps.is_prime(i)) res++;
    cout << res << endl;
  }
  
}

C++: #include <iostream>

using namespace std;

#define MAX_N (1000000)

bool is_prime[MAX_N];
int sum[MAX_N + 1];

int main()
{
    int n;
    
    for (int i = 0; i < MAX_N; i++){
        is_prime[i] = true;
    }
    
    is_prime[0] = false;
    is_prime[1] = false;
    
    for (int i = 4; i < MAX_N; i += 2){
        is_prime[i] = false;
    }
    
    for (int i = 3; i * i < MAX_N; i += 2){
        for (int j = i + i; j < MAX_N; j += i){
            is_prime[j] = false;
        }
    }
    
    sum[0] = 0;
    for (int i = 0; i < MAX_N; i++){
        sum[i + 1] = sum[i] + is_prime[i];
    }
    
    while (cin >> n){
        cout << sum[n + 1] << endl;
    }
}

C++: #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define MAX_SIZE 1000100
#define N 999999
int preme[MAX_SIZE];

int main(int argc, char *argv[]) {
	int a = 999999;
	cout << a << endl;
	for(int i = 0; i < MAX_SIZE; i++)
		if(i % 2)
			preme[i] = 1;
		else {
			preme[i] = 0;
		}
	preme[2] = 1;
	preme[1] = 0;
	for(int i = 3; i <= 999999; i += 2) {
		if(preme[i]) {
			for(int j = i + i; j <= 999999; j += i)
				preme[j] = 0;
		}
			
	}
	//freopen("data.txt", "r", stdin);
	//freopen("data_test2.txt", "w", stdout);
	int n;
	while(cin >> n){
		int count = 0;
		for(int i = 1; i <= n; i++)
			if(preme[i])
				count++;
		cout << count << endl;
	}
		
}

C++: #include <iostream>

using namespace std;

bool is_prime(int n) {
        if (n < 2) {
                return false;
        }

        int max = n / 2;
        int i;
        for (i=2; i < max; i++) {
                if (n % i == 0) {
                        return false;
                }
        }

        return true;
}

int number_of_primes_under(int n) {
        if (n < 2) {
                return 0;
        }

        int count = 1;
        int i;
        for (i=3; i <= n; i = i + 2) {
                if (is_prime(i)) {
                        count++;
                }
        }

        return count;
}
int main(void) {
        int n;
        while(cin >> n) {
                cout << number_of_primes_under(n);
                cout << endl;
        }

        return 0;
}

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

using namespace std;

int p[1000000];
int cnt[1000000];

int main()
{
  fill(p, p + 1000000, 1);
  p[0] = p[1] = 0;
  for(int i=2;i<1000000;i++)
    for(int j=i*2;j<1000000;j+=i)
      p[j] = 0;

  for(int i=1;i<1000000;i++)
    cnt[i] = cnt[i-1] + p[i];

  int n;
  while(scanf("%d", &n) != -1)
    printf("%d\n", cnt[n]);

  return 0;
}

C++: import math
import sys

def prime_calc(n):
    rootN = math.floor(math.sqrt(n))
    prime = [2]
    data = [i + 1 for i in range(2,n,2)]
    while True:
        p = data[0]
        if rootN <= p:
            return len(prime + data)

        prime.append(p)
        data = [e for e in data if e % p != 0]

def main():
    l = []

    for line in sys.stdin:
        l.append(line)        

    for line in l:
        print(prime_calc(line))

if __name__ == "__main__":
    main()

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

//素数かどうか判定する関数
bool judge( int x )
{
    int count = 0;

    for( int i = 1; i <= x; i++ )
    {
        if( x % i == 0)
            count++;
    }

    if( count == 2 )
        return true;
    else
        return false;
}

int main()
{
    int n;

    while( cin >> n )
    {
        int count = 0;

        for( int i = 1; i <= n; i++ )
        {
            if( judge(i) )
                count++;
        }

        cout << count << endl;
    }

    return 0;
}

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

int main() {
	// your code goes here
	int nu[30];
	int num;
	int count = 0;
	int max = 29;
	for(int x=0;x<30;x++){
		nu [x] = -1;
		cin >> nu[x];
		if (nu[x] == -1) {
			max = x;
			break;
		}
	}
	for (int y=0;y<max;y++) {
		num = nu[y];
		count = 0;
		
		for (int i = 1;i<=num;i++) {
		if(i%2==0) {
			//cout <<"2: "<<i<<endl;
			count ++;
			continue;
		}
		for (int j=3;j<(int)sqrt(i)+1;j=j+2) {
			if (i%j==0) {
				count ++;
				//cout <<"i: "<<i<<" j: "<<j<<endl;
				break;
			}
		}
	}
	cout << (num-count) <<endl;
	//cout << endl;
	}
	return 0;
}