Logo
(追記) (追記ここまで)

31184번 - Xingqiu's Joke 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB4313821.053%

문제

Once again, Xingqiu hides Chongyun's ice cream into a box with a strange lock. Liyue's summer has been always very hot and Chongyun suffers more because of his excessive yang (positive) energy, so he needs that ice cream desperately.

Pixiv ID: 86787400

There are two integers $a$ and $b$ on the lock. Chongyun can perform the following three types of operations any number of times:

  • Minus 1ドル$ from both $a$ and $b$;
  • Plus 1ドル$ to both $a$ and $b$;
  • Divide both $a$ and $b$ by one of their common prime factor (that is to say, divide them by a prime $g$ where $a$ and $b$ are both divisible by $g$).

The box will be unlocked if either $a$ or $b$ or both become 1ドル$. To help Chongyun gets the ice cream back as quickly as possible, please tell him the minimum number of operations needed to unlock the box.

입력

There are multiple test cases. The first line of the input contains an integer $T$ (1ドル \le T \le 300$) indicating the number of test cases. For each test case:

The first and only line contains two integers $a$ and $b$ (1ドル \le a, b \le 10^9,ドル $a \ne b$).

출력

For each test case output one line containing one integer indicating the minimum number of operations to make $a$ or $b$ or both equal 1ドル$.

제한

예제 입력 1

5
4 7
9 8
32 84
11 35
2 1

예제 출력 1

2
7
5
4
0

노트

For the first sample test case, the optimal way is $(4, 7) \rightarrow (3, 6) \rightarrow (1, 2)$.

For the second sample test case, the optimal way is to apply the first type of operation 7ドル$ times.

For the third sample test case, the optimal way is $(32, 84) \rightarrow (16, 42) \rightarrow (15, 41) \rightarrow (14, 40) \rightarrow (13, 39) \rightarrow (1, 3)$.

For the fourth sample test case, the optimal way is $(11, 35) \rightarrow (12, 36) \rightarrow (6, 18) \rightarrow (2, 6) \rightarrow (1, 3)$.

출처

Contest > Open Cup > 2021/2022 Season > Stage 9: Grand Prix of Nanjing J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /