{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eT最近蒙德城中进口了 $m$ 块奶皮酥,团长琴想要将这批奶皮酥公平地分给 $n$ 个丘丘人,当且仅当奶皮酥的数量是丘丘人数量的倍数时,才会是公平分配。众所周知琴是蒙德城数一数二的剑士,她的笛剑可以实现以下两种操作\u003c/p\u003e\n\u003cul\u003e \n \u003cli\u003e 杀死一只丘丘人\u003c/li\u003e\n \u003cli\u003e 创造出一块奶皮酥用于分配\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003e\t\t使用一次笛剑需要花费琴一个单位的体力值,琴现在想知道实现公平分配最少需要花费多少体力。\n\n$$$Tips:$$$现在为了避免丘丘人种族灭绝,禁止将丘丘人全部斩杀。\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003e有多个测试样例。 输入的第一行包含一个整数 $$$T$$$,$$$(1 \\leqslant T \\leqslant 1000)$$$表示测试用例的数量。\u003c/p\u003e\n\u003cp\u003e对于每个测试用例:一行中包含两个整数 $n$ 和 $m$ $$$(1 \\leqslant n,m \\leqslant 10^8)$$$,表示丘丘人和奶皮酥的初始数量。\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003e对于每个测试用例输出一行包含一个整数,表示实现公平分配的最小体力消耗。 \u003c/p\u003e"}},{"title":"Example","value":{"format":"HTML","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e3\n3 12\n10 6\n8 20\n\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e0\n4\n2\n\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eFor the third sample, the best way is to destroy a robot and create an energy bar. After that, we have $$$7$$$ robots and $$$21$$$ energy bars, which leads to a fair distribution.\u003c/p\u003e"}}]}