#C11484. Josephus Problem
Josephus Problem
Josephus Problem
The Josephus problem is a theoretical problem related to a certain elimination process. Given a circle of N people, every K-th person is eliminated until only one person remains. The task is to determine the position of that last remaining person.
The problem can be described by the recurrence relation in LaTeX:
\(J(1, K) = 1\)
\(J(N, K) = ((J(N-1, K) + K - 1) \mod N) + 1\) for \(N > 1\).
You are required to implement a solution that reads from the standard input and prints the result (the last remaining person's position) to standard output.
inputFormat
The input consists of two integers \(N\) and \(K\) separated by whitespace, where \(N\) is the total number of people in the circle, and \(K\) is the step rate of elimination.
outputFormat
Output a single integer which is the position of the last person remaining.
## sample5 2
3