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

Автор Tobby_And_Friends, история, 10 лет назад, По-английски

Link: https://uva.onlinejudge.org/external/117/11774.pdf

I understand that the for n == m answer is 2. But I can't figure out the solution when n != m. I mean I basically do not understand the theory behind the solution (apart from trying out for small test cases). Any help is really appreciated.

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

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

Let's decrease all numbers by 1 as real programmers do :).

Now we can observe that if we had a number x on some place then after one permutation we have . Now we just want to know what is the minimum power of n which gives 1 modulo nm - 1.

A similar problem but harder: Problem B

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

Observe grid when n=m. In this case answer is always 2. If n!=m if you look some cases you will see answer is n+m. Good luck :)