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.

saiujwal13083 | 489 |

sudeep235poojary | 302 |

VithalNakod | 272 |

AshutoshPal1 | 254 |

go__karuna | 253 |

Soseph_Jtalin | 792 |

AshutoshPal1 | 722 |

architjindal__ | 648 |

go__karuna | 577 |

ArbazGrewal | 527 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.