Distributing Identical Coins — Solution & Editorial
Stars and bars: place K−1 dividers among N stars — C(N+K−1, K−1) arrangements. Compute with factorials mod p.
Complexity: O(N + K)
Stars and bars: place K−1 dividers among N stars — C(N+K−1, K−1) arrangements. Compute with factorials mod p.
Complexity: O(N + K)