All submissions for this problem are available.
Ravi Sharma is a geek ,pursuing his B-Tech in one of the prestigious institutes of India. His birthday falls on 18th of December. This time on his birthday he decided to take all his 14 friends to watch ‘Avatar’, the most expensive movie ever released on the silver screen. So he along with his friends went to a nearby popular theatre but were shocked to see a very long queue on the Ticket Window. Even then Ravi joined the queue with hope of getting at least 3 tickets-one definitely for himself, another one for his girlfriend and remaining one for his best friend Sunny. And as said-“Fortune favours the brave.”He returned with three tickets. But now, all his friends wanted to see the movie with him and selecting some favorites out of them was always going to spoil the party.
On the back of Ravi’s mind ,it was there to take his girlfriend and Sunny to the movie but he was in a situation in which he could not express his feelings in front of his friends. So Ravi took out the solution to the problem by solving a Combinatorial problem in his mind. He told that all his friends will be playing a game the two winners of which will be accompanying him to the movie. He told all his friends (including his girlfriend and friend Sunny) to stand in a circular manner and declared that every third person will get out until only two of them remained .
This problem asks you to determine which J positions out of a circle of M should be chosen so that the J people will always remain ,if every kth person is out. Write on one line the positions which should be chosen for J people to be the winners in order that they would be chosen for termination should the activity have continued.
The first line contains the number of test cases. The following lines contain the data. The data will consist of triples (M,K,J positive integers such that M>J)
a)In the case given ,which position should his girlfriend and his friend Sunny should take if they are the last 2 persons remaining out of 14 persons if every third person gets out.
2)If the input is 10,2,5 which positions should be taken if 5 persons are to remain and every 2nd person is out?
Input: 1 41 3 2 Output: 16 31
|Time Limit:||50 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.