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
4 years, 4 months ago

No vote yet
1 vote

  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 \( ... \) or \[ ... \] to ensure proper formatting.
2 \times 3 \( 2 \times 3 \)
2^{34} \( 2^{34} \)
a_{i-1} \( a_{i-1} \)
\frac{2}{3} \( \frac{2}{3} \)
\sqrt{2} \( \sqrt{2} \)
\sum_{i=1}^3 \( \sum_{i=1}^3 \)
\sin \theta \( \sin \theta \)
\boxed{123} \( \boxed{123} \)

Comments

Sort by:

Top Newest

This is a classic application of Pigeonhole. Let the terms be \(a_1\), \(a_2\), \(\dots\), \(a_n\). Consider the \(n\) sums \[ \begin{align*} s_1 &= a_1, \\ s_2 &= a_1 + a_2, \\ &\dots, \\ s_n &= a_1 + a_2 + \dots + a_n. \end{align*} \] If any of these sums are divisible by \(n\), then we are done.

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

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

Jon Haussmann - 4 years, 4 months ago

Log in to reply

nice

Shaan Ragib - 4 years, 3 months 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 - 4 years, 4 months ago

Log in to reply

Cool! :)

Sreejato Bhattacharya - 4 years, 4 months ago

Log in to reply

not a question

Rohan Lad - 4 years, 4 months ago

Log in to reply

Interesting problem. Possibly a Pigeonhole argument is needed?

Calvin Lin Staff - 4 years, 4 months ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...