Pow(x, n)
Real-world version: Zoom Stage MultiplierThe statement here is our own: the same inputs, outputs and technique.
A microscope has a motorised zoom stage. One click forward scales the magnification by factor, and one click backward undoes a forward click, so it divides the magnification by factor.
Given factor and a click count clicks, return the multiplier the stage applies overall. A positive clicks means that many clicks forward, a negative clicks means that many clicks backward, and zero clicks leave the magnification alone.
Report the multiplier rounded to 5 decimal places. The click count reaches into the billions, so a routine that turns the stage one click at a time is too slow: the number of multiplications you perform must grow with the logarithm of the click count, not with the count itself.
Examples
Example 1
- Input
- factor = 3.0, clicks = 4
- Output
- 81.0
Four forward clicks multiply by 3 four times over, giving 81.
Example 2
- Input
- factor = 2.5, clicks = -3
- Output
- 0.064
Three backward clicks divide by 2.5 three times, and 1 / 15.625 is 0.064.
Example 3
- Input
- factor = -1.5, clicks = 0
- Output
- 1.0
The stage never moves, so the magnification is untouched and the multiplier is 1.
Constraints
- -100.0 < factor < 100.0
- -2^31 <= clicks <= 2^31 - 1
- clicks is an integer
- factor is non-zero, or clicks > 0
- -10^4 <= the exact multiplier <= 10^4
- The returned value is rounded to 5 decimal places
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def zoom_multiplier(factor: float, clicks: int) -> float:public double zoomMultiplier(double factor, int clicks)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's