Every pizza has its own product identification number, which is generated as N digits on base K. That is, each digit can be any number between 0 and K-1. Some magic pizza, flavor of tomatoes, need special IDs. We say an ID is special if it contains "514" as its subsequence. For example, 50214 is such a special ID but 50216 is not. If each ID is generated randomly with equal probability given N and K, what is the probability that a special ID shows up?
Note that, a digit 51 is not counted as 5, and/or 1. So if an ID has the first digit 51, the second digit 51 and the third digit 4, this ID is NOT special.
The first line of the input file contains an integer T (1<= T<= 100) indicating the number of test cases.
For each test case, there are two integers N, K (2<= N, K<= 100) separated by a space.
For each test case, output the probability in one line with at least 6 digits after the decimal point.
3 5 10 6 10 7 10
0.008560000 0.015850000 0.025691500
Info: 本題輸出為浮點數,絕對或相對誤差 1e-6 以下視為正確
Migrated from old NTUJ.
Tmt, Ferng
No. | Testdata Range | Score |
---|