Given an integer N. The task is to find all factors of N and print the product of four factors of N such that:
- Sum of the four factors is equal to N.
- The product of the four factors is maximum.
If it is not possible to find 4 such factors then print “Not possible”.
Note: All the four factors can be equal to each other to maximize the product and there can be a large number of queries.
Input: 24 Output: Product -> 1296 All factors are -> 1 2 3 4 6 8 12 24 Choose the factor 6 four times, Therefore, 6+6+6+6 = 24 and product is maximum. Input: 100 Output: Product -> 390625 All the factors are -> 1 2 4 5 10 10 20 25 50 100 Choose the factor 25 four times.
The idea is to find factors of all numbers from 1 to N ( which is the maximum value of n ).
- An answer will be Not possible if the given is prime.
- And if the given n is divisible by 4 then answer will be pow(q, 4) where q is a quotient when n is divided by 4.
- If it is possible to find the answer then, the answer must include third last factor two times. And run a nested loop for other two factors.
Below is the implementation of the above approach:
- Find four factors of N with maximum product and sum equal to N | Set-2
- Find four factors of N with maximum product and sum equal to N
- Find three integers less than or equal to N such that their LCM is maximum
- Find a pair with maximum product in array of Integers
- Queries to find maximum product pair in range with updates
- Product of factors of number
- Maximize the product of four factors of a Number
- Distinct Prime Factors of Array Product
- Product of unique prime factors of a number
- Ways to express a number as product of two different factors
- Maximum factors formed by two numbers
- Maximum number of unique prime factors
- Smallest number k such that the product of digits of k is equal to n
- Check if the array has an element which is equal to product of remaining elements
- Find sum of even factors of a number
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.