def comb(n,k): if k > n: return 0 if n < mod: return (((int(fact[n]) * int(ifact[k])) % mod )* int(ifact[n-k])) % mod n_digits, k_digits = pe.base_repr(n, mod), pe.base_repr(k, mod) res = 1 for top, bot in zip(n_digits, k_digits): res = (res * C(top, bot)) % mod return res
def F_new(g): k = 2 d = pe.base_repr(g, 2) while True: k = fast_forward(d, k) % mod if not sum(d): return (k - 2) % mod else: k += 1 base_dec(d, k)