← Home
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func run(n, k, L int, c []float64) (float64, float64) {
	a := 1.0 / float64(k)
	up := make([]float64, L+1)
	stay := make([]float64, L+1)
	for t := 1; t <= L; t++ {
		u := a / float64(t+1)
		up[t] = u
		stay[t] = 1.0 - u
	}

	p := make([]float64, L+1)
	p[1] = 1.0

	ov := 0.0
	cLowOv := c[L+1]

	base, baseComp := 0.0, 0.0
	width, widthComp := 0.0, 0.0

	for step := 0; step < n; step++ {
		sum := 0.0
		oldL := p[L]

		for t := L; t >= 2; t-- {
			pt := p[t]
			sum += pt * c[t]
			p[t] = pt*stay[t] + p[t-1]*up[t-1]
		}

		p1 := p[1]
		sum += p1 * c[1]

		addBase := sum + ov*cLowOv
		y := addBase - baseComp
		tmp := base + y
		baseComp = (tmp - base) - y
		base = tmp

		addWidth := ov * (c[step+1] - cLowOv)
		y = addWidth - widthComp
		tmp = width + y
		widthComp = (tmp - width) - y
		width = tmp

		p[1] = p1 * stay[1]
		ov += oldL * up[L]
	}

	return base, width
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)
	var n, k int
	fmt.Fscan(in, &n, &k)

	c := make([]float64, n+3)
	for t := 1; t <= n+2; t++ {
		ft := float64(t)
		c[t] = ft * (ft + 3.0) / (2.0 * (ft + 1.0))
	}

	L := int(math.Sqrt(2.0*float64(n)/float64(k)) + 120.0)
	if L < 1 {
		L = 1
	}
	if L > n+1 {
		L = n + 1
	}

	const tol = 1e-11

	for {
		base, width := run(n, k, L, c)
		if width <= tol || L == n+1 {
			fmt.Printf("%.15f\n", base+width*0.5)
			return
		}
		nl := L * 2
		if nl > n+1 {
			nl = n + 1
		}
		L = nl
	}
}