Josephus Again !
All submissions for this problem are available.Josephus best friend Platypus challenged him to solve his problem. Can you help Josephus to solve the challenge? There are N people standing in a circle waiting to be executed numbered 1,2,3,..N. The counting out begin with 1st person standing in the circle and proceeds around the circle in a fixed direction(1->2->3...). There and M more people which are not currently part of circle and called as warrior group. In each step, current person kills next person with his sword, and chance is given to next alive person. But there is twist in Platypus problem. After above process, 1 person from warrior group joins circle in place of dead person till no one is left in warrior group. The elimination proceeds around the circle until only last person remains. Given N and M, Find last alive person? ###Input: -First line of input contains number of test cases denoted by T -For each test case you are given 2 integers N and M denoting number of people standing in circle and number of people in warrior group respectively ###Output: Give last alive person position in circle as 1 integer. ###Constraints 1<=T<=10 2<=N<=1e5 1<=M<=1e18 ###Sample Input: 3 2 6 8 5 4 1 ###Sample Output: 1 3 3 ###EXPLANATION: -Explanation of 3rd Test Case: Consider circle given as [1,2,3,4] ,1st person having the chance kills 2nd person and chance given to 3rd person. Now circle looks like [1,3,4]. After 1 person from warrior group joins, circle looks like [1,2,3,4] with chance of 3rd person. At last circle looks like 
|Time Limit:||2 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, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.