Josephus problem
Legend has it that Josephus - a famous historian of the first century - survived and became famous mathematical genius. During the Jewish war, he in the squad of 41
Jewish warrior was driven by the Romans in a cave. Preferring suicide captivity, the soldiers decided to stand in a circle and consistently kill each third of the living until, until there is a single man. However, Joseph, along with one of his supporters felt like the end of the senseless - he quickly figured out the saving space in a vicious circle, which has placed himself and his companion. And just so we know its history.
In our version, we start with what is built in terms of N
people, numbered from 1
to N
, and will exclude every k
-th until then, until only one person survives. (For example, if N = 10
, k = 3
, the first die third, then the 6
-th and then 9
-th, then 2
-nd, then the 7
-th, then the 1
-st, then the 8
-th, with the it - the 5
-th, and then the 10
-th. Thus, escape the 4
-th.)
Input
In the input file are given positive integers N
and k
. 1 ≤ N ≤ 500
, 1 ≤ k ≤ 100
.
Output
The output file should contain a single number - the number of surviving humans.