ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1024. Перестановки

WHY LCM and GCD??
Послано Bochkaryov_Pavel 25 окт 2006 00:19
Could you explain me why GCD and LCM are used in solution of this task? I don't understand it, and my solution without using them gets TL on test 11.
Re: WHY LCM and GCD??
Послано jagatsastry 24 янв 2008 01:11
Yeah people. Can anyone please elaborate on the algorithm being used(the LCM method). Even I used the straightforward method and got TLE#11. The codes posted are of little help in making me understand the algo. Thanks in advance.
Re: WHY LCM and GCD??
Послано Egor Stepanov [mikroz] 8 май 2008 14:37
heh, the answer is LCM from lengths of cycles...
Re: WHY LCM and GCD??
Послано Vedernikoff Sergey 8 май 2008 18:21
Why? This is very easy: if cycle 1 has length L1, and cycle 2 has length L2, then obviously we'll come to the initial situation after number of steps S, which should be multiple of L1 and L2, i.e. LCM of L1 and L2. Following this logic, it is straightforward that the answer to the problem is LCM (L1, L2, ..., Lp)
Re: WHY LCM and GCD??
Послано Madhav 18 июн 2008 00:38
what is this length of the cycle?Explain it please
Re: WHY LCM and GCD??
Послано nehzilrz 1 мар 2009 13:43
A*B=LCM(A,B)*GCD(A*B)
Some explanation
Послано melkiy 2 мар 2009 04:49
Write down how does a not long sequence behave when you apply operator P to it. Trace i-th number (number at the i-th place) and you'll see that the number has a period. This period is connected to the number of iterations needed to obtain  number i on the i-th place (why the relationship is so strong, think yourself). Since you need p[i]=i for all i, you must find LCM of all periods.
Re: WHY LCM and GCD??
Послано SubmitRush 12 авг 2009 13:18
If you get WA at TEST#11,
I guess you have a problem related data overflow.
use long type.
Bochkaryov_Pavel писал(a) 25 октября 2006 00:19
Could you explain me why GCD and LCM are used in solution of this task? I don't understand it, and my solution without using them gets TL on test 11.