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.


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.


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


1 2
1 -1


hide comments
_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 http://ideone.com/YMa2Ej

: 2013-06-18 13:36:37

all abt relative motion n maths thanx to @saket diwaker and @tyagi
casual 6 lines in python :D

ওয়াসী (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

The Mundane Programmer: 2013-02-17 02:29:39

easy one..........

Added by:Nikunj Jain
Time limit:0.543s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)