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

Обсуждение задачи 1032. Найдите кратное

Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано tau 26 июн 2001 21:04
Could someone help me. I've tried to solve the problem
using a classical Lee approach and for the worst case
when the numbers are very small (eg. 1 or 2), the program
takes about 4 secs on my PII-350.

The Dirichlet method of solving isn't a better solution
because it has the same complexity.

Could someone give me a hint on optimizing my algorithm or
if you got a better solution could you please forward it.

Thankz.
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано Jivko Ganev 26 июн 2001 22:51
In this problem you need to note 2 things:
1) There is always solution.
2) The solution is always a continuous sequence.
Yes, O(N) .
Послано Dinh Hong Minh 27 июн 2001 19:04
> Could someone help me. I've tried to solve the problem
> using a classical Lee approach and for the worst case
> when the numbers are very small (eg. 1 or 2), the program
> takes about 4 secs on my PII-350.
>
> The Dirichlet method of solving isn't a better solution
> because it has the same complexity.
>
> Could someone give me a hint on optimizing my algorithm
or
> if you got a better solution could you please forward it.
>
> Thankz.
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано tau 28 июн 2001 15:07
> In this problem you need to note 2 things:
> 1) There is always solution.
> 2) The solution is always a continuous sequence.

Thanks you.
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано Sun-ho, Cho 28 дек 2001 11:19
> > In this problem you need to note 2 things:
> > 1) There is always solution.
> > 2) The solution is always a continuous sequence.
>
> Thanks you.

I can't understand 2) The solution is always a continuous sequence.
What means continuous sequence?
    ex) 1.      4 5 6 7 8 9
                or
        2.      Input[4], Input[5], Input[6], Input[7], Input[8],
Input[9]?

I don't know..

Give me more hints...
It's the choice 2
Послано meoden 28 фев 2002 11:47
>     ex) 1.      4 5 6 7 8 9
>                 or
>         2.      Input[4], Input[5], Input[6], Input[7], Input[8],
> Input[9]?

It's the second one.
S[i]= (input[1]+input[2]+..+input[i]) mod n;
If you can find i such as s[i]=0; it's ok.
If not, you always find i, j: s[i]=s[j];
   The sol is input[i+1]...input[j]. OK?
Re: It's the choice 2
Послано Big Guava 9 мар 2002 10:49
Why the answer is such a sequence of input?
Is it impossible that : input[1],input[7],input[9].......
Thanks.
> It's the second one.
> S[i]= (input[1]+input[2]+..+input[i]) mod n;
> If you can find i such as s[i]=0; it's ok.
> If not, you always find i, j: s[i]=s[j];
>    The sol is input[i+1]...input[j]. OK?
>
>
Thank you!
Послано Sergey Baskakov, Raphail and Denis 10 апр 2005 15:18
I got AC.

Your explanation is perfect!

I think, I would have never invented anything better than O(n^2) myself.

Thanks once again!

rafailka.
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано Macarie 11 апр 2005 15:04
O(N) -> compute partial sums then find two with same remainder  modulo N and subtract them
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано TURAL**(SEKI OZEL TURK LISEYI) 7 мар 2006 20:26
i think you're proffessor becasuse you find algorithm that every one know..
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано Ayhan Aliyev [BOTL] 8 мар 2006 00:35
TURAL**(SEKI OZEL TURK LISEYI) писал(a) 7 марта 2006 20:26
i think you're proffessor becasuse you find algorithm that every one know..
Talking like you know everything

Edited by author 28.05.2006 01:02
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано AOTL_EKREM 30 мар 2007 22:15
what do you say
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано tiancaihb 9 авг 2009 06:52
4s on p2-350 is enough for oj
Re: Find A Multiple Problem. Anyone got a better than O(N^2) algo.?
Послано zylm 7 окт 2014 16:54
why it's always a continuous sequence?

Edited by author 07.10.2014 17:00