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

Общий форум

Find a multiple: A need a hint!
Послано Miguel Angel 10 янв 2002 07:54
I have thought this problem for a long time and i haven't obtained
nothing. In the discussion board says you can do it in O(n); but
simply i don't know :|
Re: It is very easy problem...(+)
Послано Nazarov Denis (nsc2001@rambler.ru) 10 янв 2002 20:57
> I have thought this problem for a long time and i haven't obtained
> nothing. In the discussion board says you can do it in O(n); but
> simply i don't know :|

This problem on arithmetic theory.

 Let us S be a summa of first i elements.

So,
 s:=0;
 for i:=1 to n do begin
  read(j);
  ..
  ..
  ..
  sum:=sum+j;
  ..
  ..
  ..
 end;

On each step we have two cases:
 1. sum mod n=0
 2. sum mod n=b. If there is a number A in our input data(in first i
elemnts!) so that A mod n=b then we can take number (sum-A) - it is
our answer.

As we take n numbers there is at least one answer.

For more help you can e-mail : nsc2001@rambler.ru
Re: It is very easy problem...(+)
Послано Nazarov Denis (nsc2001@rambler.ru) 10 янв 2002 20:58
> I have thought this problem for a long time and i haven't obtained
> nothing. In the discussion board says you can do it in O(n); but
> simply i don't know :|

This problem on arithmetic theory.

 Let us S be a summa of first i elements.

So,
 s:=0;
 for i:=1 to n do begin
  read(j);
  ..
  ..
  ..
  sum:=sum+j;
  ..
  ..
  ..
 end;

On each step we have two cases:
 1. sum mod n=0
 2. sum mod n=b. If there is a number A in our input data(in first i
elemnts!) so that A mod n=b then we can take number (sum-A) - it is
our answer.

As we take n numbers there is at least one answer.

For more help you can e-mail : nsc2001@rambler.ru