Given the total number of persons **n** and a number **k** which indicates that** k-1 **persons are skipped and **k ^{th}** person is killed in circle in a fixed direction.

The task is to choose the

**Input:**

The first line of input contains an integer** T** denoting the number of test cases . Then T test cases follow. Each test case contains 2 integers** n and k **.

**Output:**

For each test case, in a new line, output will be the safe position which satisfies the above condition.

**Your Task:**

This is a function problem. You are required to complete the **function josephus** that takes** two parameters n and k** and **returns **an integer denoting** safe position** .

**Constraints:**

1 <= T <= 100

1 <= k, n <= 20

**Example:
Input:**

2

3 2

5 3

3

4

**Explanation:
Testcase 1:** There are 3 persons so skipping 1 person i.e 1st person 2nd person will be killed. Thus the safe position is 3.

Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

akhyasharma01 | 467 |

ASWATHAMA | 399 |

john_wick | 360 |

mmzeineddine | 295 |

PiyushPandey4 | 271 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

rahulnishad96 | 442 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.