401733: GYM100519 E Equal Digits
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
E. Equal Digitstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
For the given integer N and digit D, find the minimal integer K ≥ 2 such that the representation of N in the positional numeral system with base K contains the maximum possible consecutive number of digits D at the end.
InputThe input contains two integers N and D (0 ≤ N ≤ 1015, 0 ≤ D ≤ 9).
OutputOutput two integers: K, the answer to the problem, and R, the the number of consecutive digits D at the end of the representation of N in the positional numeral system with base K.
ExamplesInput3 1Output
2 2Input
29 9Output
10 1Input
0 4Output
2 0Input
90 1Output
89 2