Smallest Base With All Ones
You are given a decimal integer n as a string.
A base k is called a good base of n if:
- k >= 2
- the representation of n in base k contains only digit 1
Return the smallest good base of n as a string.
A number made of all 1s in base k looks like:
1
11
111
1111
and so on
Example 1:
Input: n = "13"
Output: "3"
Explanation:
13 in base 3 is written as 111.
Example 2:
Input: n = "21"
Output: "4"
Explanation:
21 in base 4 is written as 111.
Now Your Turn!
Pick the correct output for the given inputInput: n = "31"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- n.length >= 1
- n represents a valid decimal integer
- 3 <= n <= 1018
- n has no leading zeros
- Output must be returned as a string