SPEED - Circular Track

no tags 

Two persons are running on a circular track either in the same direction or in the opposite direction, indefinitely. The speed of both of them is given to you. Speed will be positive in clockwise direction, and negative in anticlockwise direction. Print the number of distinct points, at which they will meet on the circle.

Input

First line contains T, number of test cases. Each test case contains two integers, S1 and S2 (not equal to zero) which are the speeds of the two persons. S1 and S2 will be distinct.

Edited: All the numbers fit in signed 32-bit integer.

Output

Print in a separate line, the number of distinct points at which they meet.

Example

Input
2
1 2
1 -1

Output
1
2

hide comments
r0bo_dart: 2015-06-25 13:47:41

math, math and math + Euclidean algorithm for gcd

AMIT KUMAR YADAV: 2015-06-17 15:22:22

SPEED THRILLS ;P

_R0b_: 2015-04-27 10:12:25

hint - gcd

Ashish Sareen: 2014-10-29 12:49:30

Cool One!!

humblefool_2: 2014-05-25 21:37:23

I dont understand the test cases..what does "meet at distinct points mean"?

Omar ِAlsherbini: 2014-01-31 00:21:15

I think the question should have told us more about the type of the variables, S1 and S2.

harshil sukhadia: 2013-10-30 02:57:25

i think something is missing because if they run indefinitely and have distinct speeds than they will meet infinite times...??

nsaini: 2013-08-19 20:42:23

getting WA
pls check my code <snip>

Last edit: 2023-05-24 20:21:07
ওয়াসী (Wasi): 2013-05-09 07:06:06

solved it with 0.10 run time on python 3.2.3
thanks for all the testcases specially @saket diwakar


Added by:Nikunj Jain
Date:2011-07-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All