Problem:
Score : 300 points

Problem Statement

Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them:

Throw the die. The current score is the result of the die.

As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up.

The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0.

You are given N and K. Find the probability that Snuke wins the game.

Constraints

1 ≤ N ≤ 10^5

1 ≤ K ≤ 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3 10

Sample Output 1

0.145833333333

If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^4 = \frac{1}{48}.

If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^3 = \frac{1}{24}.

If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \frac{1}{3} \times (\frac{1}{2})^2 = \frac{1}{12}.

Thus, the probability that Snuke wins is \frac{1}{48} + \frac{1}{24} + \frac{1}{12} = \frac{7}{48} \simeq 0.1458333333.

Sample Input 2

100000 5

Sample Output 2

0.999973749998

Solution in Scala (2.13.1) (judge verdict: Accepted)

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, K = sc.nextInt()
  val head :: tail = loop(K, List(K, Int.MaxValue))

  @scala.annotation.tailrec
  def loop(div: Int, acc: List[Int]): List[Int] = {
    if (div == 1) acc else {
      val d = math.ceil(div / 2.0).toInt
      loop(d, d :: acc)
    }
  }

  @scala.annotation.tailrec
  def counts(head: Int, list: List[Int], acc: List[Int]): List[Int] = {
    list match {
      case List() => acc
      case x :: xs if head < N && x <= N => counts(x, xs, (x - head) :: acc)
      case x :: xs if head <= N && N < x => counts(x, xs, (N - head + 1) :: acc)
      case x :: xs => counts(x, xs, 0 :: acc)
    }
  }

  val powCounts = counts(head, tail, List.empty)
  val denominator = powCounts.zipWithIndex.reverse.collectFirst {
    case (count, i) if 0 < count => math.pow(2.0, i) * N
  }.getOrElse(1.0)
  val molecule = powCounts.reverse.zipWithIndex.collect {
    case (count, i) if 0 < count => math.pow(2.0, i) * count
  }.sum
  println(molecule / denominator)
}