题目描述
Given positive integers B, K and n, find a positive integer x satisfying the following conditions:
- x is a positive integer in base B.
- x is a multiple of K.
- Among all such x, cntn(x) is minimized, where cntn(x) is defined as the sum of the n-th powers of the digits of x in base B. For example, in base 10, cnt2(114)=12+12+42=18.
Since x can be very large, you only need to output the minimum value of cntn(x).
输入格式
The input contains three positive integers B(2≤B≤103), K(2≤K≤106) and n(1≤n≤10) on a single line, separated by spaces.
输出格式
Output a single integer, the minimum possible value of cntn(x).
样例输入 #1
2 5 1
样例输出 #1
2
样例输入 #2
10 2 1
样例输出 #2
1
样例输入 #3
99 999 2
样例输出 #3
2