import math


def approximate_parameters(T):
    """
    Creates L and k parameters from papers, based on how many iterations need to be
    performed, and how much memory should be used.
    """
    log_memory = math.log(10000000, 2)
    log_T = math.log(T, 2)
    L = 1
    if (log_T - log_memory > 0):
        L = math.ceil(pow(2, log_memory - 20))

    # Total time for proof: T/k + L * 2^(k+1)
    # To optimize, set left equal to right, and solve for k
    # k = W(T * log(2) / (2 * L))  / log(2), where W is the product log function
    # W can be approximated by log(x) - log(log(x)) + 0.25
    intermediate = T * math.log(2) / (2 * L)
    k = max([round(math.log(intermediate) - math.log(math.log(intermediate)) + 0.25), 1])

    # 1/w is the approximate proportion of time spent on the proof
    w = math.floor(T / (T/k + L * pow(2, k+1))) - 2
    w = max(w, 0)

    return (L, k, w)