Brutal force on binary search to get each range of the multiplication
scala\n  def sumOfFlooredPairs(nums: Array[Int]): Int = {\n    val len = nums.length\n    if (len == 1) return 1\n    import scala.collection.mutable.HashMap\n 
```scala\n  def sumOfFlooredPairs(nums: Array[Int]): Int = {\n    val len = nums.length\n    if (len == 1) return 1\n    import scala.collection.mutable.HashMap\n    val cache = new HashMap[Int, Long]\n    nums.sortInPlaceWith(_ <= _)\n    val total = nums.reduce(_ + _).toLong\n\n    def f(v: Int, k: Int): Int = {\n      val target     = v * (k + 1) - 1\n      var start, mid = 0\n      var end        = len - 1\n      var res        = -1\n      while (start <= end) {\n        mid = (start + end) / 2\n        if (nums(mid) <= target) {\n          res = Math.max(res, mid)\n          start = mid + 1\n        } else {\n          end = mid - 1\n        }\n      }\n      if (target > nums(len - 1) + v) Integer.MAX_VALUE else res\n    }\n\n    (nums\n      .map(curr => {\n        cache.getOrElse(\n          curr, {\n            var tmp  = 0L\n            var last = -1\n            var k    = 0\n            var next = f(curr, k)\n            while (next != last || next != Integer.MAX_VALUE) {\n              if (next != Integer.MAX_VALUE)\n                tmp += (next - last) * k\n              last = next\n              k += 1\n              next = f(curr, k)\n            }\n            cache.put(curr, tmp)\n            tmp\n          }\n        )\n      })\n      .sum % (Math.pow(10, 9) + 7)).toInt\n\n  }\n```
[]