Given an integer X, the task is to find the three distinct integers greater than 1 i.e. A, B and C such that (A * B * C) = X. If no such triplet exists then print -1.
Input: X = 64
Output: 2 4 8
(2 * 4 * 8) = 64
Input: X = 32
No such triplet exists.
Approach: Suppose we have a triplet (A, B, C). Notice that, for their product to be equal to X, each of the integer has to be a factor of X. So, store all the factors of X in O(sqrt(X)) time using the approach discussed in this article.
There will be at most sqrt(X) factors now. Next, iterate on each factor by running two loops, one picking A and another picking B. Now if this triplet is valid i.e. C = X / (A * B) where C is also a factor of X. To check that, store all the factors in an unordered_set. If a valid triplet is found then print the triplet else print -1.
Below is the implementation of the above approach:
3 5 7
- Minimum product of k integers in an array of positive Integers
- Maximum product of a triplet (subsequence of size 3) in array
- Largest triplet product in a stream
- Find N integers with given difference between product and sum
- Find a triplet that sum to a given value
- Find a triplet in an array whose sum is closest to a given number
- Find two distinct prime numbers with given product
- Find any K distinct odd integers such that their sum is equal to N
- Find K distinct positive odd integers with sum N
- Find N distinct integers with zero sum
- Find N distinct integers with sum N
- Print all distinct integers that can be formed by K numbers from a given array of N numbers
- Find a pair with maximum product in array of Integers
- Maximum GCD of N integers with given product
- Find a triplet such that sum of two equals to third element
- Find triplet with minimum sum
- Pythagorean Triplet with given sum
- Count triplet pairs (A, B, C) of points in 2-D space that satisfy the given condition
- Triplet with a given sum in BST | Set 2
- Pythagorean Triplet with given sum using single loop
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.