I need berifly explain of (k — 1) / (y — 1) this formula ? what is the use case of this ?
| # | User | Rating |
|---|---|---|
| 1 | Kevin114514 | 3722 |
| 2 | Benq | 3676 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3196 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | maroonrk | 153 |
| 2 | Qingyu | 152 |
| 3 | nik_exists | 151 |
| 4 | AmShZ | 147 |
| 4 | maspy | 147 |
| 6 | Um_nik | 144 |
| 7 | Errichto | 139 |
| 8 | adamant | 136 |
| 9 | BledDest | 134 |
| 10 | AksLolCoding | 132 |
I need berifly explain of (k — 1) / (y — 1) this formula ? what is the use case of this ?
| Name |
|---|



In one operation we keep $$$(y-1)$$$ numbers, then delete $$$1$$$ (at position $$$y$$$).
Among the first $$$k$$$ kept numbers there are $$$\left\lfloor \frac{k-1}{y-1} \right\rfloor$$$ full groups, so that many numbers were deleted before them.
Therefore $$$\texttt{old_pos}$$$ = $$$k + \left\lfloor \frac{k-1}{y-1} \right\rfloor$$$ or kept $$$k$$$ + deleted before it.
Can you explain more the second line ?
basically think like this if we distribute all numbers in chunk of y numbers then we will have something like this [1 ... y]. [y+1 ...2y] and then we can see that for every block we remove 1 number so
think like this removed before curr=no of blocks in first curr-1 elements and we know that each block has size of y-1 so no of blocks=(curr-1)/(y-1) and lets name this as increment so our new k= old_k + inc
Thanks. Now it makes sense. But 1 thing why cur-1 ?
curr represent the position in current sequence we care about and we want to know how many numbers before it total numbers before curr are 1-----curr-1 if you count them it comes out to be curr-1
Let $$$y = 3$$$ → pattern in original positions: keep, keep, delete, keep, keep, delete, …
Kept positions: $$$1, 2, 4, 5, 7, 8, …$$$
Take $$$k = 5$$$ (fifth kept element): - First $$$5$$$ kept: $$$1, 2, 4, 5, 7$$$
Before it, $$$4$$$ kept numbers: $$$1,2,4,5$$$
$$$\left\lfloor\frac{k-1}{y-1}\right\rfloor = 4/2 = 2$$$ → two full groups → $$$2$$$ deletions before
Think about this way In the forward operation for every y number we keep y — 1 number and remove the last one
1 2... y y+1... 2y 2y+1... 3y
Becomes
1,2,...y-1 y+1,...,2y-1 2y+1... 3y -1
So in the reverse operation
For every y -1 number we keep y numbers
Thats why we divide by y-1 instead of y
The extra number is added at the right of every y numbers so the number added right after k doesnt matter Thats why we use k-1 instead of k
Forward operation k -= k/y
Reverse operation k += (k-1)/(y-1)