1. 程式人生 > >URAL 1521 War Games 2 樹狀陣列解決約瑟夫環,輸出離隊順序

URAL 1521 War Games 2 樹狀陣列解決約瑟夫環,輸出離隊順序

In accordance with this scheme, the war games are divided into N phases; and N soldiers, successively numbered from 1 to N, are marching round a circle one after another, i.e. the first follows the second, the second follows the third, ..., the (N-1)-th follows the N-th, and the N-th follows the first. At each phase, a single soldier leaves the circle and goes to clean the WC, while the others continue to march. At some phase, the circle is left by a soldier, who is marching K
positions before the one, who left the circle at the previous phase. A soldier, whose number is K, leaves the circle at the first phase.