SOURCE

function BaoShu(n, k) {
    if (k === 1) return n;
    let start = 0, left = n, travel = 1;
    let deleted = new Array(n).fill(0);
    while (left > 1) {
        start = (start + 1) % n;
        while (deleted[start]) {
            start = (start + 1) % n;
        }
        travel++;
        if (travel === k) {
            deleted[start] = 1;
            travel = 0;
            left--;
        }
    }
    for (let i = 0;i < n;i++) {
        if (deleted[i] === 0) {
            return i + 1;
        }
    }
}

const n = 6;
const k = 1;
console.log(BaoShu(n, k))
console 命令行工具 X clear

                    
>
console