Great Geek Game-show 3000!

Time limit1sMemory limit128 MB

Summary
Given a random permutation of N names, each contestant follows its cycle up to K steps; find the probability every cycle has length at most K.
Level

Medium5 of 10

Topics
Combinatorics, Math, Probability, Simulation
Solved
No attempts yet

Problem

You have finally been chosen to compete in the "Great Geek Game-show 3000". Any prize is split among all of the contestants, but because your strategy beats random guessing by a wide margin, you can talk everyone into following it — and keep most of the winnings for yourself.

The rules are as follows. On the stage there are NN boxes. Each box holds the name of exactly one of the NN contestants, and every contestant's name appears in exactly one box, so the boxes form a permutation of the contestants. The contestants come on stage one at a time. Each contestant may look inside at most KK boxes. If a contestant finds their own name in one of those boxes, they leave the stage and the next contestant enters. If every contestant finds their own name, everyone wins; if even one of them fails, everyone loses. No communication is allowed once the game begins, but the contestants may agree on a strategy in advance.

Opening KK boxes at random wins only rarely, so you propose a better plan. Number the contestants and the boxes 1,…,N1, \dots, N. Each contestant first opens the box with their own number. The number found inside that box tells them which box to open next, then they open the box whose number was inside that one, and so on. A contestant keeps following this chain until they either find their own number or have opened KK boxes.

If everyone follows this strategy, compute the probability that all of the contestants win.

Input

A single line contains two integers NN and KK.

  • 1≤N≤10 000 0001 \le N \le 10\,000\,000 — the number of contestants.
  • 1≤K≤N1 \le K \le N — the number of boxes each contestant may open.

Output

Print the probability that everyone wins when all contestants follow the strategy, rounded to exactly six digits after the decimal point.

Examples4

  1. Example 1

    Input
    4 2
    
    Expected output
    0.416667
    
  2. Example 2

    Input
    2 1
    
    Expected output
    0.500000
    
  3. Example 3

    Input
    6 5
    
    Expected output
    0.833333
    
  4. Example 4

    Input
    137 42
    
    Expected output
    0.029351