A problem in May Lunchtime 2014, Codechef.com

So i was trying to solve this problem.

 You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist.

What i did was simply generate the combinations and check if each of them was divisible by its cardinality. This solution turned out just fine.

After the competetion i found an elegant solution here.

It so turns out that i cannot generate a sequence of n numbers without having a consecutive subset which is not a multiple of n.

That is to say, whatever combination of numbers i try..there always exists a consecutive subset which is a multiple of 'No. of numbers'(n).

Can anyone explain this theoritically? Or is there any theorem that states this?

PS: I already tried Googling it...all in vain.

Note by Varshith Reddy
5 years, 1 month ago

No vote yet
1 vote

</code>...<code></code> ... <code>.">   Easy Math Editor

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold

- bulleted
- list

  • bulleted
  • list

1. numbered
2. list

  1. numbered
  2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1

paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
    # 4 spaces, and now they show
    # up as a code block.

    print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in </span>...<span></span> ... <span> or </span>...<span></span> ... <span> to ensure proper formatting.
2 \times 3 2×3 2 \times 3
2^{34} 234 2^{34}
a_{i-1} ai1 a_{i-1}
\frac{2}{3} 23 \frac{2}{3}
\sqrt{2} 2 \sqrt{2}
\sum_{i=1}^3 i=13 \sum_{i=1}^3
\sin \theta sinθ \sin \theta
\boxed{123} 123 \boxed{123}

Comments

Sort by:

Top Newest

This is a classic application of Pigeonhole. Let the terms be a1a_1, a2a_2, \dots, ana_n. Consider the nn sums s1=a1,s2=a1+a2,,sn=a1+a2++an. \begin{aligned} s_1 &= a_1, \\ s_2 &= a_1 + a_2, \\ &\dots, \\ s_n &= a_1 + a_2 + \dots + a_n. \end{aligned} If any of these sums are divisible by nn, then we are done.

Otherwise, each of these sums are congruent to one of 1, 2, \dots, n1n - 1 modulo nn. There are nn sums and n1n - 1 possible residues modulo nn, so by Pigeonhole, two residues must be the same. In other words, there exist ii and jj, i<ji < j, such that sisj(modn)s_i \equiv s_j \pmod{n}. Then sjsi=ai+1+ai+2++ajs_j - s_i = a_{i + 1} + a_{i + 2} + \dots + a_j is divisible by nn, as desired.

Furthermore, the example a1=a2==an1=1a_1 = a_2 = \dots = a_{n - 1} = 1 shows that you need at least nn terms to guarantee that you can find a sum of consecutive terms that are divisible by nn.

Jon Haussmann - 5 years, 1 month ago

Log in to reply

Oh. I first though to apply Pigeonhole to a different part of the problem. @Sreejato Bhattacharya remember that Pigeonhole trick/thing you showed me? By the way I'm totally showing that to the class. :D

Finn Hulse - 5 years, 1 month ago

Log in to reply

Cool! :)

Sreejato Bhattacharya - 5 years, 1 month ago

Log in to reply

nice

shaan ragib - 5 years ago

Log in to reply

Interesting problem. Possibly a Pigeonhole argument is needed?

Calvin Lin Staff - 5 years, 1 month ago

Log in to reply

not a question

Rohan Lad - 5 years, 1 month ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...