Suppose there are currently 5 elements, the deletion interval is 3, and the sequence to be deleted is 3, 6, 2, 5, 1 (note that the number here starts from 1). If you delete in this order, you will find that some elements have not been transferred. For example, after the first round of deletion, the third element will be deleted, but it will not be turned around. This is because after the first round of deletion, the position of the third element becomes the second position, so it will not rotate in the next round of deletion.
Similarly, if there are currently $n$ elements and the deletion interval is $n$, no elements will be transferred, because the positions of all elements will remain the same after each round of deletion.
If we want to find the last remaining element, we can use the following code:
int n,m;
int findLast(int n,int m) {
int RES = 0;
for(int I = 2; I < = n; i++) {
RES =(RES+m)% I;
}
Return to res
}
Where n represents the number of elements and m represents the deletion interval. The return value of this function is the position of the last remaining element (note that it is numbered from 0).
For example, if there are five elements and the deletion interval is 3, the position of the last remaining element is findlast (5,3) and the return value is 3.
I hope these contents can help you!