Back to problems

Count Positive Pairs Satisfying 1/x + 1/y = 1/N

Algorithm · Microsoft · Medium

Examples Example 1 Example 2 Requirements For a positive integer N no larger than 10^6, determine how many ordered pairs of positive integers (x, y) satisfy: Certain cases use N = 10^6 and require a result in under a second. Checking every possible combination of x and y with two loops is too slow and will time out. Notes Transform the equation as follows: Therefore, each acceptable (x, y) is obtained from a decomposition $$N^{2} = a \cdot b$$, where a = x - N and b = y - N…

Checking your access…