#P8671. [蓝桥杯 2018 国 AC] 约瑟夫环

[蓝桥杯 2018 国 AC] 约瑟夫环

Description

The nn people are numbered 1n1 \sim n. If they stand in a circle clockwise in order of their numbers, starting from the person numbered 11, they count clockwise.

(The counting starts from 11.) When the count reaches kk, that person leaves the circle. The next person starts counting again from 11.

Find the number of the last remaining person. This is the famous Josephus Circle problem.

In this problem, given nn and kk, you need to find the number of the last remaining person.

Input Format

The input is one line containing two integers n,kn,k separated by spaces.

Output Format

Output one integer, representing the number of the last remaining person.

10 3
4

Hint

0<n,k<1060<n,k<10^6.

Time limit: 1 second, 256M. The 9th Lanqiao Cup National Contest in 2018.

Translated by ChatGPT 5