[Java] Count all frequencies, then enumerate all floor values, O((distinct value count) * max)
We don\'t know the value of nums[i] / nums[j], but we can fix the value of nums[i] / nums[j], then find how many times will this value occurs.\njava\nclass Solu
We don\'t know the value of `nums[i] / nums[j]`, but we can fix the value of `nums[i] / nums[j]`, then find how many times will this value occurs.\n```java\nclass Solution {\n    public int sumOfFlooredPairs(int[] nums) {\n        int MOD = 1_000_000_000 + 7;\n        int n = nums.length;\n        long res = 0;\n        int[] count = new int[100_000+1];\n        for(int num : nums){\n            count[num]++;\n        }\n        //preSum of counts, for getting range count\n        int[] preSum =  new int[100_000 + 2];\n        for(int i = 1; i < preSum.length; i++){\n            preSum[i] = preSum[i-1] + count[i-1];\n        }\n        for(int i = 0; i < count.length; i++){\n            if(count[i] == 0){\n                continue;\n            }\n            int num = i;\n            for(int p = 1; p * num <= 100_000; p++){\n                int max = num * (p+1)-1;\n                int min = num * p;\n                //how many nums in the range\n                int c = preSum[Math.min(max+1, preSum.length-1)] - preSum[Math.min(min, preSum.length-1)];\n                long add = (long)c * p * count[num];\n                res += add;\n                res %= MOD;\n            }\n        }\n        return (int)res;\n    }\n}\n```
[]