def count(n, k): pn = 0 while 2**pn <= n // 2: pn -= 1 pn -= 1 bottom_leaves = n + 1 - 2 * 2**pn