Xingqiu's Joke

시간 제한2초메모리 제한1024 MB

요약
두 정수 a와 b가 주어질 때, 둘 모두에 1을 더하거나 빼거나 공통 소인수로 나누는 연산만으로 a 또는 b가 1이 되게 하는 최소 횟수를 구한다.
난이도

보통10점 중 7점

유형
수학, 정수론, 그리디, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 aa and bb on the lock. Chongyun can perform the following three types of operations any number of times:

  • Minus 11 from both aa and bb;
  • Plus 11 to both aa and bb;
  • Divide both aa and bb by one of their common prime factor (that is to say, divide them by a prime gg where aa and bb are both divisible by gg).

The box will be unlocked if either aa or bb or both become 11. 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 TT (1≤T≤3001 \le T \le 300) indicating the number of test cases. For each test case:

The first and only line contains two integers aa and bb (1≤a,b≤1091 \le a, b \le 10^9, a≠ba \ne b).

출력

For each test case output one line containing one integer indicating the minimum number of operations to make aa or bb or both equal 11.

힌트

For the first sample test case, the optimal way is (4,7)→(3,6)→(1,2)(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 77 times.

For the third sample test case, the optimal way is (32,84)→(16,42)→(15,41)→(14,40)→(13,39)→(1,3)(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)→(12,36)→(6,18)→(2,6)→(1,3)(11, 35) \rightarrow (12, 36) \rightarrow (6, 18) \rightarrow (2, 6) \rightarrow (1, 3).

예제1

  1. 예제 1

    입력
    5
    4 7
    9 8
    32 84
    11 35
    2 1
    
    예상 출력
    2
    7
    5
    4
    0