Happy Numbers
Hard
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Schoolboy Vasya has a fondness for numbers that end with his lucky digit k
. Whenever he encounters a natural number n
, he eagerly seeks a base d
(where d ≥ 2
) such that the representation of n
in base d
ends with the maximum possible sequence of the digit k
.
Your task is to develop a program that, given the numbers n
and k
, determines the base d
for which the representation of n
in base d
ends with the longest sequence of the digit k
.
Input Format
The input consists of two decimal integers n
and k
(1 ≤ n ≤ 10^{11}
; 0 ≤ k ≤ 9
).
Output Format
Output two numbers: d
— the base of the numeral system, and s
— the number of consecutive k
digits that the representation of n
ends with in this base. If there are multiple bases d
that achieve this, choose the smallest one.
Examples
Input #1
Answer #1
Submissions 1K
Acceptance rate 4%