#1862
Sum of Floored Pairs
international master · 1965 · lc hard +32 · verified · 30.7% accepted · 466 likes · top 8%
Description
Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs (i, j) with 0 <= i, j < nums.length. Return the answer modulo 109 + 7.
Example 1:
Input: nums = [2,5,9]
Output: 10
Explanation:
floor(2 / 5) = floor(2 / 9) = floor(5 / 9) = 0
floor(2 / 2) = floor(5 / 5) = floor(9 / 9) = 1
floor(5 / 2) = 2
floor(9 / 2) = 4
floor(9 / 5) = 1
We calculate the floor of the division for every pair of indices in the array then sum them up.
Example 2:
Input: nums = [7,7,7,7,7,7,7]
Output: 49
Code
1
2
3