-739397's blog

By -739397, history, 12 months ago, In English

I need berifly explain of (k — 1) / (y — 1) this formula ? what is the use case of this ?

  • Vote: I like it
  • +4
  • Vote: I do not like it

| Write comment?
»
12 months ago, hide # |
 
Vote: I like it -13 Vote: I do not like it

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.

  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Can you explain more the second line ?

    • »
      »
      »
      12 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      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

      • »
        »
        »
        »
        12 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Thanks. Now it makes sense. But 1 thing why cur-1 ?

        • »
          »
          »
          »
          »
          12 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          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

    • »
      »
      »
      12 months ago, hide # ^ |
       
      Vote: I like it -14 Vote: I do not like it

      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

      • Deleted positions before: $$$3, 6$$$
      • So old position $$$= k + 2 = 7$$$, which matches the actual fifth kept being at original position $$$7$$$.
»
12 months ago, hide # |
← Rev. 3  
Vote: I like it 0 Vote: I do not like it

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)