import java.util.*;
import java.io.*;
class Test
{
public static void main(String[] args)
{
int personNum, outFlag;
Scanner scn = new Scanner(System.in);
System.out.print("请输入人数:");
personNum = scn.nextInt();
System.out.print("请输入出圈标识数:");
outFlag = scn.nextInt();
LoopOut loopOut = new LoopOut(personNum, outFlag);
loopOut.printOutNums();
}
}
class LoopOut
{
private int personNum;
private int currentIndex = 0;
private int outFlag;
private LoopLink looplink;
public LoopOut(int personNum, int outFlag)
{
this.personNum = personNum;
this.outFlag = outFlag;
looplink = new LoopLink(personNum);
}
private void setOutFlag(int outFlag)
{
this.outFlag = outFlag;
}
private void setPersonNum(int num)
{
this.personNum = num;
}
public void printOutNums()
{
Node node = looplink.getTail();
while(looplink.getNodeNum() > 0)
{
currentIndex ++;
if(currentIndex%outFlag == 0 )
{
System.out.print("" + (node.next.data)+ " ");
looplink.popNext(node);
}
else
{
node = node.next;
}
}
}
}
class LoopLink
{
private Node head;
private Node tail;
private int nodeNum ;
public LoopLink()
{
this.head = null;
this.tail = null;
this.nodeNum = 0;
}
public LoopLink(int num)
{
this();
for(int i = 1;i <= num; ++i)
{
Node node = new Node(i);
push(node);
}
}
public Node getHead()
{
return head;
}
public Node getTail()
{
return tail;
}
public int getNodeNum()
{
return nodeNum;
}
public void push(Node node)
{
if(nodeNum == 0)
{
head = node;
tail = node;
node.next = node;
}
else
{
tail.next = node;
node.next = head;
tail = node;
}
nodeNum++;
}
public void popNext(Node preDel)
{
preDel.next = preDel.next.next;
nodeNum--;
}
}
class Node
{
int data;
Node next;
public Node(int data)
{
this.data = data;
this.next = null;
}
}