Power Eggs

View as PDF

Submit solution

Points: 15
Time limit: 1.0s
Memory limit: 16M

Problem type

Benedict bought K identical power eggs from Dropeggs.com, and now he wants to test them by dropping them from different floors of his building. His building has N floors numbered 1 to N. F is an unknown number in the range from 0 to N, inclusive. Each egg will break if dropped from floor F+1 or above, but will not break if dropped from floor F or below. Benedict can drop each egg as many times as he wants from any floor until it breaks. He wants to know the minimum number of egg drops necessary to ensure that he can determine F.

For example, if there are three floors and Benedict has only one egg, then he has to first throw the egg from the first floor, then from the second floor (if the egg survived), and then from the third floor (if the egg survived). Therefore, three drops are required in the worst case.

Input Specification

The first line contains one number T (1 \le T \le 10\,000) which is the number of test cases, followed by T lines. Each of the next T lines contains two numbers: N, the number of floors (1 \le N \le 2\,000\,000\,007) and K, the number of eggs (1 \le K \le 32).

Output Specification

For each of the T lines, print the minimal number of drops required, or if it's greater than 32, print the word Impossible. After that many drops, Benedict gets too tired and cannot continue.

Sample Input

10 1
100 2
30 30
2000000000 2

Sample Output



  • 14
    GreenRobot  commented on May 21, 2020, 2:46 p.m.

    What a great website to buy eggs off of.

  • 0
    kobortor  commented on Oct. 2, 2015, 10:18 p.m.

    Why does Benedict need 3 drops? Couldn't he infer that F = 3 after he drops the egg from the second floor and survive?

    • 1
      cheesecake  commented on Oct. 2, 2015, 11:03 p.m.

      After he drops it from the second floor and it survives, F could be either 2 or 3, since the egg survives at floor F.