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

Обсуждение задачи 1682. Чокнутый профессор

My algo
Послано Aram Shatakhtsyan (YSU) 3 май 2009 20:32
I don't know what is the fastest way to solve this, but I think mine is more complicated than it can be. I've keeped a vector for each remainder i mod k and i*i mod k, to quickly find the numbers which give remainder r. Then you can add edge by edge in graph and use union-find algo to check for cycles. Maybe there is a faster math solution?
Re: My algo
Послано SkorKNURE 14 июл 2010 23:58
Yep, graph is very sparse. Almost always (without several trivial cases) you can consider only range [0..2*k]. To avoid any kinds of checking simply get n = max(10, 2*k). For each number in [1..n] try to find cycle with previous ones. Use e.g. disjoint sets for simplicity. Note, that solution always exists!
Re: My algo
Послано pmartynov 27 июл 2014 15:40
SkorKNURE писал(a) 14 июля 2010 23:58
Almost always (without several trivial cases) you can consider only range [0..2*k]. To avoid any kinds of checking simply get n = max(10, 2*k).
Is there any mathematical proof for this?
Re: My algo
Послано Vladimir Leskov {SESC USU} 3 авг 2014 11:48
if k=1 =>ans is 3
if k=2 =>ans is 5
if k>2 => you can take numbers 1, k-1, 2*k-1, and it will be a cycle