CF2236C.Omsk Programmers

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

An annual programmers fair is taking place on the main square of Omsk. You, as the main programmer of Omsk, decided to take part in this wonderful event and went there. At the entrance, a guard decided to check your skills and gave you a problem:

You are given three integers aa, bb, xx. You want to make aa and bb equal. In order to do so, you can apply the following operations:

  1. Choose one of the integers aa or bb and add 11 to it.
  2. Choose one of the integers aa or bb and divide it by xx with rounding down.

You need to find the minimum number of operations after which aa becomes equal to bb. Can you prove your skills, or will you have to go back home?

一年一度的程序员博览会正在鄂木斯克主广场举行。作为鄂木斯克首席程序员,你决定参加这场盛大的活动并前往现场。在入口处,一名守卫决定检验你的编程能力,并向你提出以下问题:

给定三个整数 aa、bb 和 xx。你的目标是使 aa 与 bb 相等。为此,你可以执行以下两种操作之一:

  1. 选择 aa 或 bb 中的一个整数,并将其加 11;
  2. 选择 aa 或 bb 中的一个整数,并将其除以 xx(向下取整)。

你需要求出使 aa 等于 bb 所需的最少操作次数。你能否证明自己的实力,还是只能打道回府?

输入格式

The first line contains a single integer tt (1≤t≤104)(1 \le t \le 10^4) — the number of test cases.

Then tt test cases follow.

Each test case consists of a single line containing three integers aa, bb, xx (1≤a,b≤1091 \le a, b \le 10^9, 2≤x≤1092 \le x \le 10^9).

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

接下来是 tt 个测试用例。

每个测试用例由一行组成,包含三个整数 aa、bb、xx(1≤a,b≤1091 \le a, b \le 10^9,2≤x≤1092 \le x \le 10^9)。

输出格式

For each test case, output a single integer — the minimum number of operations required to make aa and bb equal.

对于每个测试用例,输出一个整数——使 aa 和 bb 相等所需的最少操作次数。

输入输出样例

  • 输入#1

    7
    1 2 3
    2 3 2
    7 3 10
    17 3 3
    10 10 2
    4 7 2
    1 6 2

    输出#1

    1
    1
    2
    3
    0
    2
    2

说明/提示

null

输入解题思路,AI测评打分。不知道怎么写?

首页