Minimize the Maximum of Two Arrays
We have two arrays arr1 and arr2 which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:
arr1containsuniqueCnt1distinct positive integers, each of which is not divisible bydivisor1.arr2containsuniqueCnt2distinct positive integers, each of which is not divisible bydivisor2.- No integer is present in both
arr1andarr2.
Given divisor1, divisor2, uniqueCnt1, and uniqueCnt2, return the minimum possible maximum integer that can be present in either array.
Example 1
Input
divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3Output
4We can distribute the first 4 natural numbers as arr1 = [1] and arr2 = [2, 3, 4], so the maximum value is 4.
Example 2
Input
divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1Output
3The arrays arr1 = [1, 2] and arr2 = [3] satisfy all conditions, so the maximum value is 3.
Constraints
- 2 <= divisor1, divisor2 <= 10^5
- 1 <= uniqueCnt1, uniqueCnt2 < 10^9
- 2 <= uniqueCnt1 + uniqueCnt2 <= 10^9