Can you solve this

Krishna_10

Commendable
Mar 29, 2016
1
0
1,510
0
Chef has bought N robots to transport cakes for a large community wedding. He has
assigned unique indices, from 1 to N, to each of them. How it will happen?
Chef arranges the N robots in a row, in the (increasing) order of their indices. Then, he
chooses the first M robots and moves them to the end of the queue. Now, Chef goes to the
robot at the first position in the row and hands it one cake. He then notes this robot's index
(say k) in his notebook, and goes to the kth position in the row. If the robot at this position
does not have a cake, he give him one cake, notes his index in his notebook, and continues
the same process. If a robot visited by Chef already has a cake with it, then he stops moving
and the cake assignment process is stopped.
Chef will be satisfied if all robots have a cake in the end. In order to prepare the kitchen
staff for Chef's wrath (or happiness :) ), you must find out if he will be satisfied or not? If
not, you have to find out how much robots have a cake, so that the kitchen staff can
prepare themselves accordingly.
Input
The first line of input contains a single integer T denoting the number of test cases.
The single line of each test case contains two space separated integers N and M.
 
Thread starter Similar threads Forum Replies Date
S Apps General Discussion 2
P Apps General Discussion 1
K Apps General Discussion 2
G Apps General Discussion 1
D Apps General Discussion 1
Rafael Mestdag Apps General Discussion 2
P Apps General Discussion 1
B Apps General Discussion 1
D Apps General Discussion 1
K Apps General Discussion 1
deramatic351 Apps General Discussion 6
L Apps General Discussion 1
L Apps General Discussion 1
tech-wreck Apps General Discussion 5
My Life Is Tech Apps General Discussion 4
M Apps General Discussion 2
drapacioli Apps General Discussion 1
delellod123 Apps General Discussion 2
P Apps General Discussion 4
nate vongrimm Apps General Discussion 2

ASK THE COMMUNITY

TRENDING THREADS