java 代码 链表的方式
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
List<Integer> list=new ArrayList<>();
for(int i=1;i<=n;i++)
list.add(i);
int c=(m-1)%n;
int i = 1;
while(list.size()!=1) {
list.remove(c);
i *= m;
c=(c + m*i -1)%list.size();
}
System.out.println(list.get(0));
}
}