시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 10 0 0 0.000%

문제

Given three values n, a, and b, find the smallest m>n such that the sum of the digits of m in base a is the same as the sum of digits of m in base b.

입력

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. There will be a single line of input, with three integers, n (0 ≤ n ≤ 1016), a and b (2 ≤ a < b ≤ 36), all of which will be in base 10.

출력

Output a single integer, m, which is the smallest number greater than n such that the sum of its digits in base a is the same as the sum of its digits in base b. Output m in base 10.

예제 입력 1

66 10 16

예제 출력 1

144

예제 입력 2

24 4 15

예제 출력 2

90

예제 입력 3

9358385 11 32

예제 출력 3

9437362