/***********************************************************
jos2.c -- Josephus (ヨセフス) の問題
***********************************************************/
#N88BASIC

Dim k As Long, n As Long, p As Long


Input "人数";n
Input "何人ごと? ";p
k = p - 1
while (k < (p - 1) * n)
k = (p * k) / (p - 1) + 1
Print p * n - k;"番の人が残ります"
Wend