← Back to Problems
Cycles of a Random Shuffle
Medium standard Combinatorics
Time limit: 3 s per test  ·  Memory: 256 MB

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.

Input

Two integers n and k.

Output

One real number: ln P(exactly k cycles), with absolute or relative error at most 1e-6.

Constraints

1 <= k <= n <= 5000

Scoring

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.

Examples

input
3 2
output
-0.693147181
input
4 1
output
-1.386294361
Python 3.13 i Execution environment Isolated microVM · 1 vCPU · no internet access Time and memory limits are set per problem Available packages numpy 2.5.0scipy 1.18.0pandas 3.0.0scikit-learn 1.9.0statsmodels 0.15.0cvxpy 1.9.2