Given N integers with unknown values (ai > 0) having product P. The task is to find the maximum possible greatest common divisor of these N integers.
Input : N = 3, P = 24 Output : 2 The integers will have maximum GCD of 2 when a1 = 2, a2 = 2, a3 = 6. Input : N = 2, P = 1 Output : 1 Only possibility is a1 = 1 and a2 = 1.
- First find all the prime factors of product P and store it in a Hashmap.
- The N integers will have maximum GCD when a prime factor will be common in all the integers.
- So if P = p1k1 * p2k2 * p3k3 …. where p1, p2 … are prime numbers then, maximum GCD which can be obtained will be ans = p1k1 / N * p2k2 / N * p3k3 / N ….
Below is the implementation of the above approach:
- Find a pair with maximum product in array of Integers
- Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k
- Find N integers with given difference between product and sum
- Find three integers less than or equal to N such that their LCM is maximum
- Maximum number of Unique integers in Sub-Array of given size
- Count positive integers with 0 as a digit and maximum 'd' digits
- Find integers that divides maximum number of elements of the array
- Maximum GCD from Given Product of Unknowns
- Breaking an Integer to get Maximum Product
- Find four factors of N with maximum product and sum equal to N | Set-2
- Find the Number of Maximum Product Quadruples
- Find four factors of N with maximum product and sum equal to N
- Maximum number with same digit factorial product
- Maximum length subarray with LCM equal to product
- Find four factors of N with maximum product and sum equal to N | Set 3
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.