AT_abc465_d.X to Y
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given integers X,Y, and an integer K that is at least 2.
There is a variable x, which is initially x=X. You can perform the following operation on x zero or more times:
- Choose an integer y satisfying ⌊Kx⌋=y or ⌊Ky⌋=x, and replace the value of x with y.
Here, ⌊z⌋ is defined as the greatest integer not exceeding z, for a real number z.
Find the minimum number of operations required to make x=Y. Under the given constraints, it can be proved that there always exists a way to make x=Y in a finite number of operations.
You are given T test cases; solve each of them.
给你整数 X、Y 和一个不小于 2 的整数 K。
有一个变量 x,其初始值为 x=X。你可以对 x 执行以下操作零次或多次:
- 选择一个整数 y,满足 ⌊Kx⌋=y 或 ⌊Ky⌋=x,然后将 x 的值替换为 y。
其中,对任意实数 z,⌊z⌋ 表示不超过 z 的最大整数。
求使 x=Y 所需的最少操作次数。在给定约束条件下,可以证明总存在一种方式,在有限步操作内使 x=Y。
你将得到 T 组测试用例,请分别求解每组。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
The i-th (1≤i≤T) test case casei is given in the following format:
X Y K
输入从标准输入中以如下格式给出:
T
case1
case2
⋮
caseT
第 i 个(1≤i≤T)测试用例 casei 以如下格式给出:
X Y K
输出格式
Output the answers for the test cases in order, separated by newlines.
按顺序输出测试用例的答案,每个答案占一行。
输入输出样例
输入#1
4 11 9 3 0 0 2 842 180 7 1948706013487601 48019760148910476 89014537
输出#1
2 0 7 5
说明/提示
Sample 1 Explanation:
Consider the first test case.
By performing the following operations, x=Y can be achieved in two operations:
- Choose y=3. Since ⌊Kx⌋=⌊311⌋=3, this choice is valid. Then, replace the value of x with 3.
- Choose y=9. Since ⌊Ky⌋=⌊39⌋=3, this choice is valid. Then, replace the value of x with 9.
x=Y cannot be achieved in fewer than two operations, so output 2 on the first line.
Constraints
- 1≤T≤2×105
- 0≤X,Y≤1018
- 2≤K≤1018
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
通过执行以下操作,可以在两次操作内使 x=Y 成立:
- 选择 y=3。由于 ⌊Kx⌋=⌊311⌋=3,该选择合法。然后将 x 的值替换为 3。
- 选择 y=9。由于 ⌊Ky⌋=⌊39⌋=3,该选择合法。然后将 x 的值替换为 9。
无法在少于两次操作内使 x=Y 成立,因此第一行输出 2。
约束条件
- 1≤T≤2×105
- 0≤X,Y≤1018
- 2≤K≤1018
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?