2147483648's blog

By 2147483648, history, 11 months ago, In English

Problem statement: You are given an integer $$$N$$$ and the task is to output an integer sequence $$$a_1, \ldots, a_m$$$, such that $$$1 \leq a_i \leq N$$$ and $$$a_i + a_j \neq a_k + a_l$$$ for $$$i \neq j, k \neq l, (i,\ j) \neq (k,\ l)$$$ (i. e. all $$$\frac{m(m-1)}{2} $$$ pairwise sums should be different). The goal is to maximize $$$m$$$ — the length of resulting sequence.

This problem comes from RUCODE recent competition, it had a requirement for answer $$$m \geq \frac{\sqrt{N}}{2}$$$. Also there was a requirement for $$$a_i \neq a_j,\ i \neq j$$$, but in reality in makes almost no sense since if $$$m \geq 3$$$ and if $$$a_i == a_j$$$ for some $$$i \neq j$$$, than $$$a_k + a_i == a_k + a_j$$$ for any $$$k \neq i,\ k \neq j$$$. Since case $$$m < 3$$$ is obvious, we will further assume that all numbers in a sequence are different.

The solution to this problem comes from the fact that...

Spoiler

So, if we take largest prime $$$p$$$ that $$$2p ^ 2 + (p ^ 2 + 1) \bmod (2p) <= N$$$, we will get a sequence with $$$m \approx \sqrt{\frac{N}{2}} = \frac{\sqrt{N}}{\sqrt{2}} = lb_1(N)$$$, which is enough to solve the original problem.

Now there some interesting questions:

  1. Can we get some upper bound for $$$m$$$?

  2. How can we compute the longest possible (an optimal) sequence for some small $$$N$$$?

Here are my humble answers:

1). Since $$$a_i + a_j < 2N$$$, then by Dirichlet's principle we get $$$\frac{m(m-1)}{2} < 2N \Rightarrow m^2 < 4N \Rightarrow m < 2\sqrt{N}$$$. So our construction is $$$ub_1 = 2\sqrt{2} \approx 2.82$$$ times shorter than this upper bound.

2). I wrote a recursive bruteforce, it can find the optimal answer for $$$N = 64$$$ in about $$$10$$$ seconds.

Code

These questions brings us to some more challenging problems:

  1. Can we improve aforementioned lower bound construction? Or write some code, which will build longer sequence with some bruteforce and pruning?

  2. Can we improve above the algorithm for finding the optimal sequence? Maybe get some polynomial solution (or prove that it lies somewhere in NP class)?

  3. Can we improve upper bound for $$$m$$$?

Really wanna find some answers on these questions, appreciate any of your thoughts!

UPD1: thanks to nor, we now have an upper bound $$$m < (1 + \varepsilon) \sqrt{N} = ub_2(N)$$$, which brings us to the $$$\underset{N \to \infty}{\lim}\dfrac{ub_2(N)}{lb_1(N)} = \sqrt{2} \approx 1.41$$$ which is a massive improvement! Proof can be found here. Turns out that this problem was researched even before the era of computers!

  • Vote: I like it
  • +55
  • Vote: I do not like it

»
11 months ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

Rewrite the condition as $$$a_i-a_k\neq a_l-a_j$$$. Then, there are $$$\binom m2$$$ possible differences, and each difference is only allowed to appear at most twice. Since the difference is between $$$1$$$ and $$$N-1$$$, the inequality $$$\binom m2\leq N-1$$$ must hold, which gives the bound $$$m\leq\sqrt{2(N-1)}$$$

  • »
    »
    11 months ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Here is the table of answers for small values of N.

    Spoiler

    The first value is the optimal $$$m$$$, the second value is $$$\lfloor\sqrt{2(N-1)}\rfloor$$$. It seems that this upper bound doesn't work (at least for small N). Can you explain it on some examples? Like $$$N = 5$$$ (optimal answer $$$1\ 2\ 3\ 5$$$) or $$$N = 8$$$ (optimal answer $$$1\ 2\ 3\ 5\ 8$$$)? Why the difference can't be negative?

    • »
      »
      »
      11 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Oh $$$\binom m2\leq N-1$$$ actually implies $$$m\leq\sqrt{2(N-1)}+1$$$, which seems to be correct.

      • »
        »
        »
        »
        11 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Still not working for $$$N = 5,\ 8$$$, but $$$m \leq \sqrt{2N} + 1$$$ does the trick.

      • »
        »
        »
        »
        11 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        $$$(2m - 1)^2 = 4m(m - 1) + 1 \le 8(N - 1) + 1 = 8N - 7$$$, so $$$m \le \frac{1 + \sqrt{8N - 7}}{2}$$$, which is a stronger bound.

        @2147483648, can you post the sequence you recover for $$$N = 5, 8$$$? Something seems off.

        • »
          »
          »
          »
          »
          11 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          $$$1, 2, 3, 5$$$ for $$$N=5$$$ and $$$1, 2, 3, 5, 8$$$ for $$$N=8$$$.

          • »
            »
            »
            »
            »
            »
            11 months ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Oh, in that case, Golomb rulers have a slightly different definition, my bad. For Golomb rulers, you are allowed to have $$$i = j$$$ or $$$k = l$$$ in the restriction, so these sequences are not valid Golomb rulers, since $$$1 + 3 = 2 + 2$$$.

»
11 months ago, # |
  Vote: I like it +31 Vote: I do not like it

The sequences you're talking about are called Golomb rulers. Funnily enough, I had set a problem on them quite a while back with a similar construction as yours, and someone pointed out to me that a similar problem was on the IMO Shortlist 2001 as N6 which also mentions your construction in the official solutions (and when I looked into it further, there was a reference to that problem being on a French TST even before that, with the same construction, and the construction dates back to Erdös and Turán, much before any of these contests).

  • »
    »
    11 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Wow, huge thanks for the references! It's absolutely crazy that this problem was studied so long ago.