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
- Find N integers with given difference between product and sum
- Find two distinct prime numbers with given product
- Find a pair with maximum product in array of Integers
- Minimum product of k integers in an array of positive Integers
- Largest triplet product in a stream
- Maximum product of a triplet (subsequnece of size 3) in array
- Number of distinct integers obtained by lcm(X, N)/X
- Check if the sum of distinct digits of two integers are equal
- Queries for number of distinct integers in Suffix
- Represent (2 / N) as the sum of three distinct positive integers of the form (1 / m)
- 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
- Integers from the range that are composed of a single distinct digit
- Maximum GCD of N integers with given product
- Generate permutation of 1 to N such that absolute difference of consecutive numbers give K distinct integers
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.