Go: package main

import (
  "fmt"
  "math"
)

func main() {
  const N = 1000000
  var temp [N+1]bool
  for i:=0; i<N+1; i++ {
    temp[i] = true
  }
  temp[0] = false
  temp[1] = false
  for i:=2; i<int(math.Ceil(math.Sqrt(float64(N+1)))); i++{
    if (temp[i]){
      for j:=i*2; j<N+1; j+=i{
        temp[j] =false
      }
    }
  }
  var a int
  var b int
  for _, err := fmt.Scan(&a); err == nil; _, err = fmt.Scan(&a) {
    b = 0
    for i:=0; i<=a; i++{
      if temp[i] {
        b++
      }
    }
    fmt.Println(b)
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int prime[1000000] = {0};
    int k = 1;
    prime[0] = 2;
    for (long long int i = 3; i < 999999; i++)
    {
        double temp = sqrt(i);
        for (int j = 0; i % prime[j] != 0; j++)
        {
            if (temp < prime[j])
            {
                prime[k++] = i;
                break;
            }
        }
    }
    int n;
    int i;
    while (cin >> n)
    {
        i = 0;
        while (true)
        {
            if (n < prime[i])
            {
                break;
            }
            i++;
        }
        cout << i << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    vector<int> primes;
    primes.PB(2);
    FOR(i,3,500000){
	bool flg = true;
	REP(j,primes.size()) if(i % primes[j] == 0 ) {
	    flg = false;
	    break;
	}
	if(flg) primes.PB(i);
    }

    int n;
    while(true){
	cin >> n;
	if(cin.eof())break;
	int res = upper_bound(ALL(primes),n) - primes.begin();
	cout << res << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    vector<int> vi;
    vi.push_back(2);
    vi.push_back(3);
    for(int i=5;i<=n;i+=2){
      for(int j=3;j<=i;j+=2){
	if(i==(j/2)+1)
	  vi.push_back(i);
	if(i%j==0)
	  break;
      }
    }
    cout<<vi.size()<<endl;
  }
  return 0;
}

C++: #include <cmath>
#include <cstdlib>
#include <cstdio>

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>



int main() {

  bool isPrime[1000000];
  int  num[1000000];
  int  temp;
  int  n;

  for(int i = 0; i < 1000000; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0; i < 1000; ++i) {
    if( isPrime[i] ) {
      for(int j = i+i; j < 1000000; j += i) {
	isPrime[j] = false;
      }
    }
  }

  num[0] = num[1] = 0;
  temp = 0;
  for(int i = 2; i < 1000000; ++i) {
    if( isPrime[i] ) ++temp;
    num[i] = temp;
  }

  while( std::cin >> n ) {
    std::cout << num[n] << std::endl;
  }
  
  return 0;
}

C++: #include <iostream> 
#include <cmath>
#include <stdio.h>

                                                                                                                                                               
int count_prime_number(int);

int main(void){

    int n;
    while(scanf("%d",&n) != EOF){
        std::cout << count_prime_number(n) << std::endl; 
    }

    return 0;
}

int count_prime_number(int n){

    int f,prime_num = 1;

    if (n == 2) {
        prime_num = 1;
    }
    else{
        for (int j = 3; j <= n; j += 2) {   
            f = 0;
            for(int i = 3; i <= std::sqrt(n); i+=2){
                if (j%i == 0) {
                    f = 1;
                    break;
                }
            }

            if (f == 0) {
                prime_num++;
            }
        }
    }

    return prime_num;

}

C++: #include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;

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

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}

const int MAX_N = (int)1e6;
int prime[MAX_N];
bool is_prime[MAX_N + 1];

int main(void){
	int num = sieve(MAX_N, prime, is_prime);

	int n;
	while(scanf("%d", &n)){
		if(n == EOF) break;
		cout << upper_bound(prime, prime + num, n) - prime << '\n';
	}

	return 0;
}

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

int prime[1000000];


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


void get_prime(int max_num) {
  int primecount = 1;
  prime[2] = primecount;
  for (int i = 3; i <= max_num; i += 2) {
    if (isPrime(i))
      prime[i] = ++primecount;
    else
      prime[i] = primecount;
  }
}


int main () {
  int ns[31];
  int i = 0, max_num;
  while (std::cin >> ns[i]) {
    max_num = std::max(max_num, ns[i]);;
    if (ns[i] % 2 == 0)
      ns[i] --;
    i ++;
  }
  get_prime(max_num);
  for (int j = 0; j < i; j ++) {
    std::cout << prime[ns[j]] << std::endl;
  }
  return 0;
}

C++: #include "stdio.h"
//#include"time.h"
const int MAX_V = 1000000; // 100????????§????´???°??¨?????????
int prime[MAX_V+1]; // 1????´???°,0????´???°??§?????????
int main() {
    int i, k, n, u;
//    clock_t start, now;//??£?¨?
    for(i = 2; i <= MAX_V; i++){
        prime[i] = 1; // 2??\???????´???°??¨??????
    }
    for(i = 2; i * i <= MAX_V; i++) {
        if(prime[i]) {
            for(k = 2 * i; k <= MAX_V; k += i) {
                prime[k] = 0; // ?´???°???2?????\???????????°????´???°??§?????????
            }
        }
    }
    int sum[1000000] = {0};
    while (1) {
        scanf("%d",&n);
        for(u = 0;u <= n;u++){
            if (n == EOF)break;
            sum[u+1] = sum[u] + prime[u];
//        start = clock(); // ????§???????
//        now = clock(); // ????????????
        }
        printf("%d\n",sum[n+1]);//for?????????????????????
//        printf("%f\n", (double)(now - start) / CLOCKS_PER_SEC);
    }
    return 0;
}
//????¨??????¨????????????????????????

C++: #include <iostream>
using namespace std;
const int len = 1000000;

int main()
{
    int arr[30] = {0},n,count=0;
     cin>>n;
    for (int i = 2; i < n; i++)
    {
        for (int j = i * i; j < n; j+=i)
        {
            arr[j - 1] = 1;
        }
    }
    for (int i = 1; i < n; i++)
    {

        if ((arr[i - 1] == 0)&&(i>1))
            count++;


    }
    std::cout <<count;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
bool prime[1000000] = {false};
int main(){
    int n;
    while(cin >> n){
       
        prime[1] = true;
        prime[2] = false;
        int count = 0;
        
      
        for(int j = 2; j * j <= n ; j++){
            if(!prime[j]){
                for (int k = 2; k*j <= n;k++){
                   prime[j*k] = true;
                }
            }
        }
        for(int i = 1;i<=n;i++){
            if(!prime[i]) count = count +1;
        }
        cout << count << endl;
    }
    return 0;
}