QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#10892. 公平分配

统计

在梦之国度里有 $n$ 个机器人和 $m$ 个能量棒。国王 DreamGrid 试图对能量棒进行公平分配。当且仅当能量棒的数量是机器人数量的倍数时,即存在公平分配。

DreamGrid 唯一的工具是一把强大的激光枪。每次开启激光枪,他可以执行以下两项操作之一:

  • 制造一个新的能量棒。
  • 摧毁一个机器人。

为了避免机器人灭绝,禁止摧毁全部 $n$ 个机器人。开启一次激光枪需要花费一美元。请你求出实现公平分配所需的最小花费。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 1000$),表示测试数据的组数。对于每组测试数据:

仅一行,包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 10^8$),分别表示初始的机器人数量和能量棒数量。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示实现公平分配所需的最小花费。

样例

输入格式 1

3
3 12
10 6
8 20

输出格式 1

0
4
2

说明

对于第三个样例,最优的方法是摧毁一个机器人并制造一个能量棒。之后,我们拥有 7 个机器人和 21 个能量棒,这实现了公平分配。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.