[BOJ 13742] Base Sums
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
5
Time limit:
2.0s
Memory limit:
512M
Problem type
Allowed languages
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
Comments