# AtCoder Beginner Contest 126

URL: https://atcoder.jp/contests/abc126 (opens new window)

# C

n,k = gets.chomp.split(" ").map(&:to_i)

result = 0
(1..n).each do |i|
  # iのときの確率は (1 / n) * (1 / 2)^a
  # aは表が連続で出る回数で i * 2^a >= k を満たす最小のa (a >= 0)
  a = [(Math.log2(k) - Math.log2(i)).ceil, 0].max
  result += 1 / (n * (2 ** a)).to_f
end

puts result
Last Updated: 2020/08/18 23:38