ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Find a multiple: A need a hint!
Posted by Miguel Angel 10 Jan 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...(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 10 Jan 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...(+)
Posted by Nazarov Denis (nsc2001@rambler.ru) 10 Jan 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