|  | 
|  | 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT.    |--> | 
|  | 2 | +<!--+----------------------------------------------------------------------+--> | 
|  | 3 | +<!--|@author    openset <[email protected]>                           |--> | 
|  | 4 | +<!--|@link      https://github.com/openset                                 |--> | 
|  | 5 | +<!--|@home      https://github.com/openset/leetcode                        |--> | 
|  | 6 | +<!--+----------------------------------------------------------------------+--> | 
|  | 7 | + | 
|  | 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/web-crawler "Web Crawler") | 
|  | 9 | +                 | 
|  | 10 | +[Next >](https://github.com/openset/leetcode/tree/master/problems/circular-permutation-in-binary-representation "Circular Permutation in Binary Representation") | 
|  | 11 | + | 
|  | 12 | +## [1237. Find Positive Integer Solution for a Given Equation (Easy)](https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation "找出给定方程的正整数解") | 
|  | 13 | + | 
|  | 14 | +<p>Given a function  <code>f(x, y)</code> and a value <code>z</code>, return all positive integer pairs <code>x</code> and <code>y</code> where <code>f(x,y) == z</code>.</p> | 
|  | 15 | + | 
|  | 16 | +<p>The function is constantly increasing, i.e.:</p> | 
|  | 17 | + | 
|  | 18 | +<ul> | 
|  | 19 | +	<li><code>f(x, y) < f(x + 1, y)</code></li> | 
|  | 20 | +	<li><code>f(x, y) < f(x, y + 1)</code></li> | 
|  | 21 | +</ul> | 
|  | 22 | + | 
|  | 23 | +<p>The function interface is defined like this: </p> | 
|  | 24 | + | 
|  | 25 | +<pre> | 
|  | 26 | +interface CustomFunction { | 
|  | 27 | +public: | 
|  | 28 | +  // Returns positive integer f(x, y) for any given positive integer x and y. | 
|  | 29 | +  int f(int x, int y); | 
|  | 30 | +}; | 
|  | 31 | +</pre> | 
|  | 32 | + | 
|  | 33 | +<p>For custom testing purposes you're given an integer <code>function_id</code> and a target <code>z</code> as input, where <code>function_id</code> represent one function from an secret internal list, on the examples you'll know only two functions from the list.  </p> | 
|  | 34 | + | 
|  | 35 | +<p>You may return the solutions in any order.</p> | 
|  | 36 | + | 
|  | 37 | +<p> </p> | 
|  | 38 | +<p><strong>Example 1:</strong></p> | 
|  | 39 | + | 
|  | 40 | +<pre> | 
|  | 41 | +<strong>Input:</strong> function_id = 1, z = 5 | 
|  | 42 | +<strong>Output:</strong> [[1,4],[2,3],[3,2],[4,1]] | 
|  | 43 | +<strong>Explanation:</strong> function_id = 1 means that f(x, y) = x + y</pre> | 
|  | 44 | + | 
|  | 45 | +<p><strong>Example 2:</strong></p> | 
|  | 46 | + | 
|  | 47 | +<pre> | 
|  | 48 | +<strong>Input:</strong> function_id = 2, z = 5 | 
|  | 49 | +<strong>Output:</strong> [[1,5],[5,1]] | 
|  | 50 | +<strong>Explanation:</strong> function_id = 2 means that f(x, y) = x * y | 
|  | 51 | +</pre> | 
|  | 52 | + | 
|  | 53 | +<p> </p> | 
|  | 54 | +<p><strong>Constraints:</strong></p> | 
|  | 55 | + | 
|  | 56 | +<ul> | 
|  | 57 | +	<li><code>1 <= function_id <= 9</code></li> | 
|  | 58 | +	<li><code>1 <= z <= 100</code></li> | 
|  | 59 | +	<li>It's guaranteed that the solutions of <code>f(x, y) == z</code> will be on the range <code>1 <= x, y <= 1000</code></li> | 
|  | 60 | +	<li>It's also guaranteed that <code>f(x, y)</code> will fit in 32 bit signed integer if <code>1 <= x, y <= 1000</code></li> | 
|  | 61 | +</ul> | 
|  | 62 | + | 
|  | 63 | +### Related Topics | 
|  | 64 | +  [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | 
|  | 65 | +  [[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)] | 
|  | 66 | + | 
|  | 67 | +### Hints | 
|  | 68 | +<details> | 
|  | 69 | +<summary>Hint 1</summary> | 
|  | 70 | +Loop over 1 ≤ x,y ≤ 1000 and check if f(x,y) == z. | 
|  | 71 | +</details> | 
0 commit comments