Algorithm for evaluating a sequence while removing from that sequence?

27 Views Asked by At

Introduction : I'm looking at this problem and I've gotten stuck on it. The rules are as follows:

Problem Definition :

  1. You have a sequence of numbers -- 1 through x (where x > 1).

  2. Two numbers are randomly chosen from the sequence (y & z).

  3. The product of y and z should equal the sum of all numbers in the sequence (minus y and z).
  4. If you know the value of x, could we create an algorithm that tells me all possible values of y and z?

Example :

x = 26

y = 15 or 21

z = 21 or 15

Proof :

The sum of x = x*(x+1)/2;

In this case, the sum of x = 351

351 - (15 + 21) = 315

315 = 15 * 21 315 - 21 * 15

What I've tried so far:

I've tried writing an algorithm in Java to solve this with loops and if statements but, when the values of x get too big, it causes a memory overflow.

I then tried looking at existing solutions to similar problems and adapting the algorithms with mathematics to my solution, but the issue is that it seems many existing solutions don't really explain why they work.

Side notes :

As an aside, this isn't a homework problem (I'm not even in school anymore). This is just something I'm trying to do for enrichment.

To clarify, I don't want a programming solution. I want to understand how to do this mathematically.

Does anybody have any clues? I've been working on this for about a day now and figured it was time to reach out for help.

1

There are 1 best solutions below

0
On

Here is something that I observed:

Given $x$ we want to find $y,z$ such that the following holds:

$$yz = \frac{x(x+1)}{2}-y-z\iff yz+y+z +1= \frac{x(x+1)}{2}+1\iff (1+y)(1+z)=\frac{x^2+x+2}{2}.$$

So I guess you could compute $(x^2+x+2)/2$ and factorize it to obtain possible values for $y$ and $z.$

When $x=26$ then $(x^2+x+2)/2 = 352 = 2^5 \times 11 = (1+y)(1+z).$

This gives a couple of possibilities, but you want to impose the constraint that $1\leq y,z\leq x = 26.$ So for instance, $y=10, z=31$ is not valid. But, $y=21 = 2\times 11-1, z=2^4-1$ is as you have already mentioned.