public static int josheph(int x, int num) {
// 数组初始化全为true
boolean[] a = new boolean[x];
for (int i = 0; i < x; i++) {
a[i] = true;
}
int count = 0;
int index = 0;
int len = x;
while (len > 1) {
if (a[index] == true) {
count++;
if (count == num) {
count = 0;
a[index] = false;
len--;
}
}
index++;
if (index == x) {
index = 0;
}
}
// 遍历找到最后一个为true的元素
for (int i = 0; i < a.length; i++) {
if (a[i]) {
return i;
}
}
return -1;
}