7

I am trying to solve the following problem on integer sequences and subset sums from a 2023 Shanghai high school entrance exam:

Let $A = (a_1, a_2, \dots, a_n)$ be a sequence of positive integers such that $$ \sum_{i=1}^n a_i = 2013 $$ Find the minimum value of $n$ such that every possible sequence of length $n$ satisfying the sum constraint contains a consecutive sequence of elements whose sum is exactly $31$ (e.g., $a_4 + a_5 + \dots + a_{10} = 31$).

Allegedly, fewer than 100 students managed to solve this problem rigorously.


Latest progress (what we need now)

While we have found a construction for $n=1021$, and proved $n=1021$ isn't ok, I am looking for a rigorous proof that $n=1022$ is the minimum. Specifically:

  1. (Solved) Prove for every $n<1022$ that there exists a sequence that doesn't satisfy the condition [contains a consecutive sequence of elements whose sum is exactly $31$].

  2. How do I rigorously prove that any sequence of length $1022$ with sum $2013$ must contain a consecutive sum of $31$?


My first thought

I suspect we need to analyze the "worst-case scenario"—that is, constructing a sequence that avoids having a subset sum of $31$ with the maximum possible length. If I can find the maximum length $n_{\max}$ that fails the condition, then the answer should be $n_{\max} + 1$. Intuitively, to maximize the length of the sequence without reaching the total sum too quickly, we need small numbers. I think we need many occurrences of $1$ in this sequence, but we can't have thirty-one $1$s, for otherwise the sum $31$ is trivial. How do I formalize the construction of the sequence that avoids $31$ to find the threshold?

  • 1
    Perhaps you could construct smaller examples with answers by substantially reducing the $2013$ and $31$? For example, with $7$ and $3$ I think the answer is $n=4$ (since $5+1+1$ does not work), while with $8$ and $3$ I think the answer is $n=5$ (since $2+2+2+2$ does not work). – Henry Nov 25 '25 at 14:39

3 Answers3

9

We have $n > 32\cdot 31 + 29 = 1021$ (since $1021$ still doesn't satisfy the property), which gives

\begin{equation} n \ge 1021 + 1 = \boxed{1022} . \end{equation}

Take $32$ copies of $$\underbrace{1,\dots,1}_{30},32$$ and then append $$\underbrace{1,\dots,1}_{29},$$ yielding $$\sum_{i=1}^{1021} a_i = 32\cdot 62 + 29 = 2013.$$

RobPratt
  • 52,643
  • Maybe answer is 1021+1=1022 – thedeepdeepsky Nov 26 '25 at 13:38
  • Since 1021 still doesn't satisfy the property – thedeepdeepsky Nov 26 '25 at 13:39
  • 1021 Seems correct as the largest unsatisfying number – thedeepdeepsky Nov 26 '25 at 14:13
  • 3
    Proof of correctness. Consider your set of prefix sums P. Your sequence A will have no subsequence of sum 31 iff no two members of P have a difference of 31. Divide the numbers 0 to 2013 into conjugacy classes mod 31. 30 of those conjugacy classes will have 65 elements, 1 will have 64; picking alternating members of each conjugacy class and including them in P gives 3330+32 elements of P, or 3330+31 = 1021 elements of A. That is the best you can do, because adding another member of P implies there is some class containing two consecutive members, which will then have a difference of 31 – Craig Nov 26 '25 at 15:42
2

The smallest $n$ with this property is 992. First of all, 991 does not have the property, since we can take $a_1=a_2=\ldots=a_{990}=2$ and $a_{991}=33$. Since the only odd number in the sequence is $33$, no subset can sum to $31$. Similarly, for $n<991$ we can pick $a_1=a_2=\ldots=a_{n-1}=2$ and $a_n=2013-2n+2$.

And if $n=992$ then there must be an odd number $m$ in the sequence less than 31. If not, then there must be an odd number, which is then at least 33, and all other numbers are at least 2, which sums to at least $991\cdot 2+33=2015$. Then, since the majority of the numbers is equal to 1 or 2, we can add $2$'s and pairs of $1$'s to $m$ to make $31$.

Matthew Spam
  • 1,027
  • 2
  • 7
1

RobPratt's answer has already proved @$n=1021$,this sequence contains no consecutive subsegment summing to 31.This answer is to proof subquestion 1


We want to prove that if a valid sequence exists for length $N$, a valid sequence exists for length $N-1$.

Let a sequence $A = (a_1, a_2, \dots, a_N)$ be a sequence of positive integers summing to 2013 that avoids the subsegment sum 31. Let $P = \{0, s_1, s_2, \dots, s_N\}$ be the set of prefix sums of this sequence, where $s_k = \sum_{i=1}^k a_i$.

The statement "no consecutive subsegment sums to 31" is mathematically equivalent to: $$ \text{For all } x, y \in P, \quad |x - y| \neq 31 $$


To create a sequence of length $N-1$, we simply merge two adjacent terms $a_i$ and $a_{i+1}$ into a single term $(a_i + a_{i+1})$.

  • The total sum remains 2013.
  • The length becomes $N-1$.
  • In terms of prefix sums, merging $a_i$ and $a_{i+1}$ corresponds to removing the prefix sum $s_i$ from the set $P$.

$\therefore$ If the original set of prefix sums $P$ contained no two numbers with a difference of 31, then any subset $P' \subset P$ also contains no two numbers with a difference of 31. Removing a prefix sum (shortening the sequence) cannot create a new difference of 31; it can only remove existing differences.


  1. We have explicitly constructed a valid sequence for $n=1021$ that avoids the sum 31.
  2. By merging adjacent terms arbitrarily, we can derive a valid sequence for $n=1020, 1019, \dots, 1$.
  3. Therefore, for every positive integer $n < 1022$, there exists a sequence summing to 2013 with no consecutive subsegment sum of 31.