题目收集
题目列表题单
返回列表

ez-version

CodeforcesP0034· 1000ms· 256 MB· ZJU Summer 2026 Contest 3原题链接
数论同余最短路

创建于 2026/07/16 · 更新于 2026/07/16

题目描述

Given positive integers BBB, KKK and nnn, find a positive integer xxx satisfying the following conditions:

  • xxx is a positive integer in base BBB.
  • xxx is a multiple of KKK.
  • Among all such xxx, cntn(x)\mathrm{cnt}_n(x)cntn​(x) is minimized, where cntn(x)\mathrm{cnt}_n(x)cntn​(x) is defined as the sum of the nnn-th powers of the digits of xxx in base BBB. For example, in base 101010, cnt2(114)=12+12+42=18\mathrm{cnt}_{2}(114)=1^2+1^2+4^2=18cnt2​(114)=12+12+42=18.

Since xxx can be very large, you only need to output the minimum value of cntn(x)\mathrm{cnt}_n(x)cntn​(x).

输入格式

The input contains three positive integers B(2≤B≤103)B(2\leq B\leq 10^3)B(2≤B≤103), K(2≤K≤106)K(2\leq K\leq 10^6)K(2≤K≤106) and n(1≤n≤10)n(1\leq n\leq 10)n(1≤n≤10) on a single line, separated by spaces.

输出格式

Output a single integer, the minimum possible value of cntn(x)\mathrm{cnt}_n(x)cntn​(x).

样例输入 #1

2 5 1

样例输出 #1

2

样例输入 #2

10 2 1

样例输出 #2

1

样例输入 #3

99 999 2

样例输出 #3

2