---
# System prepended metadata

title: 1283. Find the Smallest Divisor Given a Threshold
tags: [Leetcode, Binary Search, Medium]

---

# 1283. Find the Smallest Divisor Given a Threshold
###### tags: `Leetcode` `Medium` `Binary Search`
Link: https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold/
## 思路 $O(NlogM)$ $O(1)$
## Code
```java=
class Solution {
    public int smallestDivisor(int[] nums, int threshold) {
        int max = 0;
        for(int num:nums) max = Math.max(max, num);
        int start=1, end=max;
        while(start<end){
            int mid = start+(end-start)/2, sum=0;
            for(int num:nums) sum += (num+mid-1)/mid;
            if(sum>threshold){
                start = mid+1;
            }
            else end = mid;
        }
        return start;
    }
}
```