1862. Sum of Floored Pairs Hard

@problem@discussion
#Array#Math#Binary Search#Prefix Sum



1/**
2 * [1862] Sum of Floored Pairs
3 *
4 * Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 10^9 + 7.
5 * The floor() function returns the integer part of the division.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [2,5,9]
10 * Output: 10
11 * Explanation:
12 * floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0
13 * floor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1
14 * floor(5 / 2) = 2
15 * floor(9 / 2) = 4
16 * floor(9 / 5) = 1
17 * We calculate the floor of the division for every pair of indices in the array then sum them up.
18 * 
19 * Example 2:
20 * 
21 * Input: nums = [7,7,7,7,7,7,7]
22 * Output: 49
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= nums.length <= 10^5
28 * 	1 <= nums[i] <= 10^5
29 * 
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/sum-of-floored-pairs/
34// discuss: https://leetcode.com/problems/sum-of-floored-pairs/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39    pub fn sum_of_floored_pairs(nums: Vec<i32>) -> i32 {
40        0
41    }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_1862() {
52    }
53}
54


Back
© 2025 bowen.ge All Rights Reserved.