x and y are positive integers and x + y + xy = 54, x + y =?

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/u014064071/article/details/100036315

Happened to see this topic, think of using sql to achieve lower.

Ideas are as follows:

   Two cycles, an integer corresponding traverse directly. (Which may be replaced with the function portion corresponding to the conditional expressions, just to try writing custom function).

The present embodiment uses a database oracle10, it can operate normally.

- custom function

- test their defined functions

--- sql statement section 

A total of more than three sections.

 

- defined functions
Create or Replace function myFunction (Number X in, Y in Number)
  return Number IS
the begin
  IF (X + Y * Y + X) = 54 is the then
    return. 1;
  the else
    return -. 1;
  End IF;
End;
 
- testing their function defined

SELECT myFunction (11,4) from Dual;
 
--- SQL statement segment 

DECLARE
  X Number;
  Y Number;
the begin
   X: =. 1;
  the while (X <54 is) Loop
    Y: =. 1;
    the while ( Y <53 is) Loop
      IF myFunction (X, Y) =. 1 the then - either directly write IF (X + Y * Y + X) = 54 is the then
        the DBMS_OUTPUT.PUT_LINE (X || '***** ** results *** '|| Y);
      End IF;
      Y: = Y +. 1;
    end loop;
    x := x + 1;
  end loop;
end;

----

Guess you like

Origin blog.csdn.net/u014064071/article/details/100036315