First Register Overflow Tick
Problem statement
An unsigned bits-bit register initially contains zero. At each unit tick, add the same positive integer increment. The first addition is at tick 1.
Overflow occurs when the mathematical sum would exceed 2^bits - 1. Return the first tick at which overflow occurs. Do not wrap the stored value before deciding whether that tick overflows.
Function
firstOverflowTick(bits: int, increment: int) → longExamples
Example 1
bits = 8increment = 10return = 26Tick 25 would store 250, while tick 26 would store 260 above the maximum 255.
Example 2
bits = 8increment = 255return = 2Tick 1 reaches the valid maximum 255; tick 2 is the first overflow.
Example 3
bits = 4increment = 20return = 1The maximum is 15, so the first addition already overflows.
Constraints
1 <= bits <= 31.1 <= increment <= 10^9.- The result is a positive signed 64-bit integer.