res
to 0, which will count the number of operations.i
to 1, which represents the index we are tracking (since the permutation starts at 0).i
returns to 1:
a. If i
is less than n / 2
, then i
becomes i * 2
.
b. If i
is greater than or equal to n / 2
, then i
becomes (i - n / 2) * 2 + 1
.
c. Increment res
by 1 after each simulation step.i
returns to 1, and res
is the result.