Given a positive integer N, the task is to represent the fraction 2 / N as the sum of three distinct positive integers of the form 1 / m i.e. (2 / N) = (1 / x) + (1 / y) + (1 / z) and print x, y and z.
Input: N = 3
Output: 3 4 12
(1 / 3) + (1 / 4) + (1 / 12) = ((4 + 3 + 1) / 12)
= (8 / 12) = (2 / 3) i.e. 2 / N
Input: N = 28
Output: 28 29 812
Approach: It can be easily inferred that for N = 1, there will be no solution. For N > 1, (2 / N) can be represented as (1 / N) + (1 / N) and the problem gets reduced to representing it as a sum of two fractions. Now, find the difference between (1 / N) and 1 / (N + 1) and get the fraction 1 / (N * (N + 1)). Therefore, the solution is (2 / N) = (1 / N) + (1 / (N + 1)) + (1 / (N * (N + 1))) where x = N, y = N + 1 and z = N * (N + 1).
Below is the implementation of the above approach:
5 6 30
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.
- Maximum number of distinct positive integers that can be used to represent N
- Check whether a number can be represented as sum of K distinct positive integers
- Find K distinct positive odd integers with sum N
- Represent a number as the sum of positive numbers ending with 9
- Different ways to represent N as sum of K non-zero integers
- Add two integers of different base and represent sum in smaller base of the two
- Number of distinct ways to represent a number as sum of K unique primes
- Count of integers up to N which represent a Binary number
- Number of arrays of size N whose elements are positive integers and sum is K
- Ways to write N as sum of two or more positive integers | Set-2
- Number of ways in which N can be represented as the sum of two positive integers
- Print all possible ways to write N as sum of two or more positive integers
- Check if a number can be written as sum of three consecutive integers
- Number of quadruples where the first three terms are in AP and last three terms are in GP
- Count 'd' digit positive integers with 0 as a digit
- Count positive integers with 0 as a digit and maximum 'd' digits
- Find n positive integers that satisfy the given equations
- Check whether product of integers from a to b is positive , negative or zero
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
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.