QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#10965. Transforming Pairs

统计

Answer $Q$ ($1\le Q\le 10^5$) independent queries each of the following form: You are given four integers $a,b,c,d$ ($-10^{18}\le a,b,c,d\le 10^{18}$). In one operation you can either do $a\mathrel{+}=b$, or $b\mathrel{+}=a$. Determine the minimum number of operations to transform $(a,b)$ into $(c,d)$, or if it is impossible to do so, output $-1$.

Input Format

The next $Q$ lines each contain four integers $a,b,c,d$.

Output Format

The answer for each query on a separate line.

Sample Data

Sample Input

4
5 -3 -1 -3
5 3 5 2
5 3 8 19
5 3 5 3

Sample Output

2
-1
3
0

Sample Explanation

First query: $(5,-3)\to (2,-3)\to (-1,-3)$ Second query: Impossible. Third query: $(5,3) \to (8, 3) \to (8, 11) \to (8, 19)$ Fourth query: No operations necessary.

Constraints

  • Input 2: $|a|, |b|, |c|,|d|\le 10$
  • Input 3: $a,b\ge 0$
  • Input 4: $a \geq 0 \geq b$
  • Input 5: $a \leq 0 \leq b$
  • Input 6: $a,b\le 0$
  • Input 7: $c,d\ge 0$
  • Input 8: $c \geq 0 \geq d$
  • Input 9: $c \leq 0 \leq d$
  • Input 10: $c,d\le 0$
  • Inputs 11-14: $Q \leq 10^3$
  • Inputs 15-19: No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.