def solutionClosed(n: int, p: float) -> float:
	"""
	A closed-form solution to solutionRecursive's recurrence relation.
	Derivation:
	Let q = (-2p + 1).
		h[0] = 1,
		h[n] = q h[n-1] + p.
	By iterating,
		h[1] = q + p,
		h[2] = q (q + p) + p = q^2 + pq + p,
		h[3] = q (q^2 + pq + p) + p = q^3 + pq^2 + pq + p,
		h[n] = q^n + p(q^(n-1) + q^(n-2) + ... + q^0).
	Because the term p(q^(n-1) + q^(n-2) + ... + q^0) is a geometric series,
		h[n] = q^n + p(1 - q^n)/(1 - q).
	Substituting q = (-2p + 1) and simplifying,
		h[n] = ((-2p + 1)^n + 1)/2.
	"""
	return ((-2*p + 1)**n + 1)/2