F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Fxx and game

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4542    Accepted Submission(s): 1246


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\leq T\leq20)$ indicating the number of test cases.

As for the following $T$ lines, each line contains three integers $X,k,t(0\leq t\leq10^6,1\leq X,k\leq10^6)$

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
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 08:40:36, Gzip enabled