Double Until Limit
Mediumjava
Start from a value and repeatedly do x *= 2 until x is greater than or equal to a limit. Print how many doublings were needed and the final value.
Input: two integers start and limit separated by whitespace (start >= 1).
Output: one line: <number of doublings> <final value>. If start is already >= limit, the answer is 0 <start>.
Example 1
Input
3 20
Output
3 24
- 1 <= start <= 1000000
- 1 <= limit <= 1000000000
Hint 1
Loop while x < limit, doubling x with x *= 2 and incrementing count each time.
Hint 2
If the loop never runs, count stays 0 and x is unchanged.
Each pass multiplies x by 2 via compound assignment and counts one doubling. The loop condition x < limit means that if start already meets the limit, no doublings happen.