Problem Description
Young theoretical computer scientist Fxx designed a game for his students.
In each game, you will get three integers X,k,t.In each step, you can only do one of the following moves:
1.X=X−i(0<=i<=t).
2.if k|X,X=X/k.
Now Fxx wants you to tell him the minimum steps to make X become 1.
Input
In the first line, there is an integer T(1≤T≤20) indicating the number of test cases.
As for the following T lines, each line contains three integers X,k,t(0≤t≤106,1≤X,k≤106)
For each text case,we assure that it’s possible to make X become 1。
Output
For each test case, output the answer.
Sample Input
2
9 2 1
11 3 3
Sample Output
4
3
题目大意:给出三个数x,k,t,对于这个数x,我们有两种变化,:
1,我们可以让x减去一个数y,其中 0<=y<=t
2,如果x是k的倍数,那么我们可以让x=x/k
每一次我们可以选择以上两种操作之一,问从x到1的最小变化次数是多少。
解题思路:这个题我们可以很容易的推出状态转移公式,
dp[j]=min(dp[i])+1 (其中0<=j-i<=t)
if(j%k==0) dp[j]=</