# Josephus problem

# Josephus problem

Legend has itthatJosephus-a famoushistorianof the first century-survivedandbecame famousmathematicalgenius.Duringthe Jewishwar, hein thesquadof**41**Jewishwarriorwasdrivenby the Romansina cave.Preferringsuicidecaptivity,the soldiersdecided tostand ina circleandconsistentlykilleachthirdofthe livinguntil,until there isa single man.However,Joseph, alongwith oneof hissupportersfeltlikethe end of thesenseless-hequicklyfigured outthe savingspacein a viciouscircle,whichhas placed himselfandhis companion.Andjustso weknowits history.

Inourversion, westartwithwhatis built interms of**N**people,numbered from**1** to**N**,andwillexcludeevery**k**-thuntilthen,untilonly onepersonsurvives.(For example, if**N** = **10**, **k** =**3**, thefirstdiethird,thenthe **6**-thand then**9**-th,then **2**-nd,thenthe **7**-th,thenthe **1**-st,thenthe **8**-th, with theit - the**5**-th,andthenthe **10**-th.Thus,escapethe **4**-th.)

**Input**

In the inputfileare givenpositive integers**N** and **k**. **1** ≤ **N** ≤ **500**, **1** ≤ **k** ≤ **100**.

**Output**

The outputfileshouldcontaina single number- the number ofsurvivinghumans.

10 3

4