Блог пользователя parimal7

Автор parimal7, история, 4 года назад, По-английски

I tried reading the editorial but cannot understand the solution to this problem

The main point which I cannot understand is why should S % gcd(N,K) be equal to 0?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Assuming that the throne is on position 0, then our current position becomes S. If we're moving in a circle then we are bound to follow a cyclic path. So we need both 0 and S to be on the same path.

In a cycle of length 'n', if you jump by 'k' steps then you can move as follows:

0 => gcd(n, k) => 2*gcd(n, k) => ....... (See this for yourself)

So, iff S % gcd(n, k) = 0, 0 can be reached from S after some moves.