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:7
Output:2
Explanation:

7 in base 2 is 111 (1×4 + 1×2 + 1×1 = 7). Base 2 is the smallest such base.

Input:57
Output:7
Explanation:

57 in base 7 is 111 (1×49 + 1×7 + 1×1 = 57). Base 7 is the smallest such base.

Constraints

  • 3 ≤ n ≤ 10¹⁸

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!