parimal7's blog

By parimal7, history, 4 years ago, In English

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?

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.