Time limit
2s
Memory limit
128 MB
There is an N-story building. For some threshold floor F, dropping a safe from floor F or any higher floor always breaks it, while dropping it from any lower floor never breaks it. The safe may also survive a drop from floor N, and it may break starting from floor 1.
You have K identical safes and want to determine this threshold by dropping safes. A broken safe cannot be used again; a safe that does not break can be reused.
Let E(N, K) be the minimum number of drops needed to determine F in the worst case, no matter where F is. If K=1, you must test floors in increasing order until the safe would break, so E(N, 1)=N.
Given N and K, compute E(N, K).
The first line contains two integers N(1 <= N <= 500) and K(1 <= K <= N).
Print E(N, K) on the first line.