This page is still under construction.

Parts of this page are still being built. What you see may change.

Birthday Party

Time limit5sMemory limit256 MB

Summary
Each of N guests gives a present to a random other guest, and you must compute the probability that some k guests form a directed gift cycle.
Level

Hard8 of 10

Topics
Combinatorics, Probability, Math
Solved
No attempts yet

Problem

NN people are invited to a birthday party. Each of them brings one present, and the person who receives that present is picked at random. Nobody gives a present to themselves, and each of the other N−1N-1 people is equally likely to be picked. The choices are independent, so one guest can receive several presents while another receives none.

Call a gift cycle a set of kk distinct guests p1,p2,…,pkp_1, p_2, \dots, p_k such that p1p_1 gives their present to p2p_2, p2p_2 gives theirs to p3p_3, and so on until pkp_k gives theirs back to p1p_1. Find the probability that at least one gift cycle of length kk appears.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers NN and kk separated by a space.

  • 0<T≤300 < T \le 30
  • 2≤N≤1072 \le N \le 10^7
  • 2≤k≤N2 \le k \le N

Output

For each test case, print the probability on its own line, rounded to exactly six digits after the decimal point. Print 1.000000 when the probability is 11, and 0.313470 when it is 0.313469843…0.313469843\ldots

Examples1

  1. Example 1

    Input
    4
    2 2
    3 2
    3 3
    10 3
    
    Expected output
    1.000000
    0.750000
    0.250000
    0.313470