---
# System prepended metadata

title: 2513. Minimize the Maximum of Two Arrays
tags: [Leetcode, Medium, Math]

---

# 2513. Minimize the Maximum of Two Arrays
###### tags: `Leetcode` `Medium` `Math`
Link: https://leetcode.com/problems/minimize-the-maximum-of-two-arrays/description/
## 思路
[思路参考](https://leetcode.com/problems/minimize-the-maximum-of-two-arrays/solutions/2947014/formula/)

## Code
```python=
class Solution:
    def minimizeSet(self, divisor1: int, divisor2: int, uniqueCnt1: int, uniqueCnt2: int) -> int:
        def getMax(cnt: int, d1: int, d2=1) -> int:
            lcm = math.lcm(d1, d2)
            return cnt+cnt//(lcm-1)-(1 if cnt%(lcm-1)==0 else 0)
        return max(getMax(uniqueCnt1, divisor1), getMax(uniqueCnt2, divisor2), getMax(uniqueCnt1+uniqueCnt2, divisor1, divisor2))
    
```