A permutation of 1..n is drawn uniformly at random. Every permutation decomposes into disjoint cycles. Compute the natural logarithm of the probability that the permutation has exactly k cycles.
Two integers n and k.
One real number: ln P(exactly k cycles), with absolute or relative error at most 1e-6.
1 <= k <= n <= 5000
This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.
Numeric answers are accepted if they are within an absolute tolerance of 1e-06 or a relative tolerance of 1e-06 of the expected value.
3 2
-0.693147181
4 1
-1.386294361