import math


def _estimate_prime_gap(n: int) -> float:
    """Returns an estimate for the average gap between the first n primes.

    Formula is based on a result derived from the Prime Number Theorem:
    https://en.wikipedia.org/wiki/Prime_number_theorem
    """

    log_n = math.log(n)
    log_log_n = math.log(log_n)
    log_n_sqr = log_n**2
    log_log_n_sqr = log_log_n**2
    return (log_n + log_log_n - 1 + (log_log_n - 2)/log_n
            - (log_log_n_sqr - 6 * log_log_n + 11)/(2 * log_n_sqr)
            + math.exp(1)/log_n_sqr)