/*
Author:lxrmido
Website:buzhuanggeek.com
Edit:GVIM_073
Date:2011/09/10
*/
import javax.swing.*;
class hw_12{
public static void main(String[] args){
String ms = JOptionPane.showInputDialog(null, "请输入围圈的人数m:");
while(!(ms.matches("\\d+")))
ms = JOptionPane.showInputDialog(null, "输入有误,请重新输入围圈的人数m:");
String ns = JOptionPane.showInputDialog(null, "请输入出圈号码n:");
while(!(ns.matches("\\d+")))
ns = JOptionPane.showInputDialog(null, "输入有误,请重新输入出圈号码n:");
int m = Integer.parseInt(ms);
int n = Integer.parseInt(ns);
boolean cir[] = new boolean[m];
StringBuilder sorted = new StringBuilder("出圈子的顺序为:\n");
for(int i = 0; i < m; i ++)
cir[i] = true;
int j = 0, k = 0;
for(int i = 0; i < m; i ++){
while(j < n){
while(cir[k] == false){
k++;
if(k == m)
k = 0;
}
j++;
k++;
if(k == m)
k = 0;
}
if(k == 0)
k = m-1;
else
k --;
sorted.append((k+1)+" ");
if((i+1)%30 == 0)
sorted.append("\n");
cir[k] = false;
j = 0;
}
JOptionPane.showMessageDialog(null, sorted+"。");
System.exit(0);
}
}