Given n, find x, y, z such that x, y, z satisfy the equation “2/n = 1/x + 1/y + 1/z”
There are multiple x, y and z that satisfy the equation print anyone of them, if not possible then print -1.
Input : 3 Output : 3 4 12 Explanation: here 3 4 and 12 satisfy the given equation Input : 7 Output : 7 8 56
Note that for n = 1 there is no solution, and for n > 1 there is solution x = n, y = n+1, z = n·(n+1).
To come to this solution, represent 2/n as 1/n+1/n and reduce the problem to represent 1/n as a sum of two fractions. Let’s find the difference between 1/n and 1/(n+1) and get a fraction 1/(n*(n+1)), so the solution is
2/n = 1/n + 1/(n+1) + 1/(n*(n+1))
x is 7 y is 8 z is 56
Time complexity: O(1)
We can write 2/n = 1/n + 1/n. And further as 2/n = 1/n + 1/2n + 1/2n.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the minimum value of m that satisfies ax + by = m and all values after m also satisfy
- Find numbers a and b that satisfy the given conditions
- Find n positive integers that satisfy the given equations
- Find the Number of Permutations that satisfy the given condition in an array
- Count Distinct Non-Negative Integer Pairs (x, y) that Satisfy the Inequality x*x + y*y < n
- Number of sextuplets (or six values) that satisfy an equation
- Count of sub-sequences which satisfy the given condition
- Pairs from an array that satisfy the given condition
- Count triplet pairs (A, B, C) of points in 2-D space that satisfy the given condition
- Count all possible N digit numbers that satisfy the given condition
- Count index pairs which satisfy the given condition
- Count of N digit numbers possible which satisfy the given conditions
- Count of indices in an array that satisfy the given condition
- Satisfy the parabola when point (A, B) and the equation is given
- Append two elements to make the array satisfy the given condition
- Pair of integers (a, b) which satisfy the given equations
- Count of Fibonacci pairs which satisfy the given equation
- Count of unordered pairs (x, y) of Array which satisfy given equation
- Minimum increment/decrement operations required on Array to satisfy given conditions
- Mimimum number of leaves required to be removed from a Tree to satisfy the given condition
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m