Description
Given integer n as string, find the smallest base k (k >= 2) such that n in base k has all digits equal to 1.
Examples
Input:
n = "13"Output:
"3"Explanation:
13 in base 3 is 111.
Input:
7Output:
2Explanation:
7 in base 2 is 111 (1×4 + 1×2 + 1×1 = 7). Base 2 is the smallest such base.
Input:
57Output:
7Explanation:
57 in base 7 is 111 (1×49 + 1×7 + 1×1 = 57). Base 7 is the smallest such base.
Constraints
- •
3 ≤ n ≤ 10¹⁸