we are given 1....n numbers. lets say we are to save a given number element k for last in elimination. We start eliminating them in the following manner. I eliminate 1 at first. Then eliminate the next kth element (index k+1). and then keep doing the same wrapping around n if needed. The numbers eliminated before dont count for elimination for counting till k, next time onwards. I want to find such k that element given element no (say i) goes last in the elimination.
as sample : lets take 1 2 3 4 5 as input
now say i want to save 5 for last. Thus min number k=3 in this case (ans)
Lets simulate it.
1 is eliminated first
4 goes next
3 goes next
2 goes next
and 5 is saved for last.
I need to find this minimum (k=3) given n and number i to save for last.