Due to the floor function many values will remain the same. Thus values will for $a_{i}$ will only have to be recomputed after an interval. $$a_{n} = x. \left\lfloor\dfrac{a_{n}}{x}\right\rfloor+r$$ $$a_{n} = (x1). \left\lfloor\dfrac{a_{n}}{x}\right\rfloor+\left(r+1.\left\lfloor\dfrac{a_{n}}{x}\right\rfloor\right)$$ $$a_{n} = (x2). \left\lfloor\dfrac{a_{n}}{x}\right\rfloor+\left(r+2.\left\lfloor\dfrac{a_{n}}{x}\right\rfloor\right)$$ $$a_{n} = (x3). \left\lfloor\dfrac{a_{n}}{x}\right\rfloor+\left(r+3.\left\lfloor\dfrac{a_{n}}{x}\right\rfloor\right)$$ $$.$$ $$.$$ $$.$$ $$a_{n} = (xm). \left\lfloor\dfrac{a_{n}}{x}\right\rfloor+\left(r+m.\left\lfloor\dfrac{a_{n}}{x}\right\rfloor\right)$$ This will be valid until the remainder is less than the divisor, thus for the next $ m$ iterations the value dosent have to be updated. $$\therefore xm\leq r+m.\left\lfloor\dfrac{a_{n}}{x}\right\rfloor $$ $$\therefore \dfrac{xr}{\left\lfloor\dfrac{a_{n}}{x}\right\rfloor +1}\leq m$$ I used a vector of vectors, where the $i^{th}$ index points to the list of values that are to be updated on the $i^{th}$ iteration. So once u compute m , you can append the index of the person in the $(i+m)^{th}$ position on this array. link to my solution asked 14 Mar, 20:55
