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
dwij28: 2015-12-26 01:37:21

Test cases are relatively weak. My highly UN-optimised / slow code gave 0.0 seconds..

darkhire21: 2015-10-26 19:33:00

don't mention hint in comments ...!!

impossible_1: 2015-09-24 08:12:26

euclidean algorithm of gcd .......then easy.

shubham agrawal: 2015-08-15 12:55:51

s1 and s2 will be distinct always..
read carefully..
at (0,2)
output will be 1

xpshekhar: 2015-08-11 22:48:43

can anyone please tell what will be output at (1,1) or (0,2)

MishThi: 2015-08-05 22:45:16

Nice concept. :P

anuveshkothari: 2015-07-26 17:27:49

you have to find all the distinct points where they can meet until they meet again at starting point after some time..
in java..
with Scanner - 0.09
with BufferedReader - 0.05

Last edit: 2015-07-26 17:53:04
SangKuan: 2015-07-02 07:33:04

nice math

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


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