Round Table Killers
Practice
4.4 (82 votes)
Basic programming
Easy
Problem
52% Success 10784 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

There is a round table in which N people are sitting. You can look at the image for their seating arrangement. Initially the person numbered X holds a gun. In addition to it there is a special number K that helps in determining the persons to be killed. The killing starts as follows - Firstly the person numbered X starts and he kills a total of \(X \% K\) people sitting clockwise of him and he gives gun to the person i who is sitting just next to the last person killed. Now that person also kills the next \(i \% K\) people and this goes on. If at any instant the total persons that are remaining is not greater than \(i \% K\) where i is the number of person holding the gun then the person i wins. You can show that sooner or later only one person remains. So your job is to decide which numbered person will win this killing game.
\(X \% K \) is the remainder when X is divided by K
Input
First line contains three numbers N , K and X as input.
Output
In the output you have to tell the number of the player who will be the winner.
Constraints
\(1\le N \le 10^3\)
\(2 \le K \lt N\)
\(1 \le X \le N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
41 votes
Tags:
AlgorithmsSortingString Manipulation
Points:10
45 votes
Tags:
Basic ProgrammingBasics of ImplementationData Types and Array handlingEasyImplementation
Points:10
280 votes
Tags:
ApprovedBasic ProgrammingEasy