How to determine if x and y exist in a set of integers X that satisfies the equation

I just stumbled upon an exam question, getting ready for an exam, and I was stuck on it. The question arises:

Develop an algorithm that, given the set of natural numbers X, determines whether the equation x 5 + xy - y 2 = y 3 has a solution with x and y belonging to X.

There is no programming, just an algorithm design. Could you share your ideas?

Brute force is unacceptable

+5
source share
4 answers

pseudo code:

result = false
foreach (x in X) {
    foreach (y in X) {
        if (x^5 + x*y - y^2 == y^3) result = true
    }
}

Something more complicated than expected? If so, then a higher order term can be used x^5as follows:

Sort X as a list from least to greatest.
result = false
foreach (y in X) {
    v = y*y*(y+1)
    foreach (x in X) {
        x2 = x*x
        u = x2*x2 + x*y - v
        if (u == 0) {
            result = true
            goto [DONE]
        }
        if (u > 0) goto [NEXT]
    }
    [NEXT]
}
[DONE]
+2

(!) :

  • ;
  • , formula. , , x, y, . , , , . (O (logn)).

O (nlogn), (, , ). , ( , ), O (n).

+2

y x: http://www.wolframalpha.com/input/?i=x%5E5%2B+xy+-+y%5E2+-+y%5E3

y(x) := INSERT_EQUATION_HERE
any((y in setX) for y in y(x) for x in setX)

O (| X |), .. , .

, any , :

for x in setX:
    possibleYs = solveForY(x)
    for y in possibleYs:
        if y in setX:
            return SOLUTION:(x,y)
return NO_SOLUTION

, . x ; x y. . , x = 0, 3 y ^ 2 == y ^ 3; x = 1, 3 2-y ^ 2 == y ^ 3, x = -0,52, .. http://en.wikipedia.org/wiki/Cubic_function#General_formula_of_roots

:

, , O (1) : min (max_x_degree, max_y_degree) < 5. , , , , 4 . .

, O (1) - , , min (max_x_degree, max_y_degree) < 5.

, .

+2

If the set X is not very large, then a simple brute force algorithm can work by constructing a two-dimensional matrix.

0
source

All Articles