Ordered-Pair Checksum Sum
Problem statement
Given a positive integer n, define C(i, j) = (i % j) + (j % i), where % is the integer remainder.
Return the sum of C(i, j) over every ordered pair satisfying 1 <= i, j <= n, modulo 10^9 + 7.
Both (i, j) and (j, i) are included when the indices differ. Pairs with i = j are included and contribute 0.
Function
checksumSum(n: int) → intExamples
Example 1
n = 3return = 10For n = 3, the ordered pairs have these checksums:
| Pair | Checksum |
|---|---|
(1, 1) | 0 |
(1, 2) | 1 |
(1, 3) | 1 |
(2, 1) | 1 |
(2, 2) | 0 |
(2, 3) | 3 |
(3, 1) | 1 |
(3, 2) | 3 |
(3, 3) | 0 |
The total is 0 + 1 + 1 + 1 + 0 + 3 + 1 + 3 + 0 = 10, so the answer is 10.
Example 2
n = 1return = 0The only pair is (1,1), and both remainders are 0. The sum is 0.
Example 3
n = 4return = 24For divisors 1, 2, 3, and 4, the sums of i % j over dividends 1..4 are 0, 2, 4, and 6. Their sum is 12. Swapping the two indices gives the same sum for j % i, so the answer is 24.
Constraints
1 <= n <= 10^9.- The numeric bounds are practice assumptions; the report does not state them.
- Return the nonnegative residue in
[0, 10^9 + 6].