A calibration routine needs the floor of a k-th root without using floating-point math. Given a non-negative integer n and a positive integer k, find the largest whole number x such that x raised to the power k is at most n.
Because floating-point roots can be off by one near exact powers, you must determine x exactly.
A single line with two integers n and k.
A single integer: the largest x with x**k <= n.
Example 1
Input
27 3
Expected
3
Explanation
3 cubed is 27 which is at most 27, while 4 cubed is 64 which exceeds 27, so the answer is 3.
Example 2
Input
100 2
Expected
10
Explanation
10 squared is exactly 100 and 11 squared is 121, so the largest x with x squared at most 100 is 10.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →