import java.util.Scanner import scala.io.StdIn object Problem257 { def proc(n: Int, k: Int): Unit = { val winFirst = (n - 1) % (k + 1) != 0 if (winFirst) { myTurn(0) } else { println("0") opponentTurn() } def myTurn(claimedVal: Int): Unit = { if (claimedVal >= n) return val diff = (n - 1 - claimedVal) % (k + 1) val claim = claimedVal + diff println(claim) opponentTurn() } def opponentTurn(): Unit = { myTurn(StdIn.readInt()) } } def main(args: Array[String]) { val sc = new Scanner(System.in) val n = sc.nextInt() val k = sc.nextInt() proc(n, k) } }