Checksum Aggregator
In a distributed network system, data packets with unique identifiers and checksum values are sent between nodes to maintain communication and data integrity. Develop a function to aggregate the checksum values for all possible pairs of packets within the network.
For any two distinct packets with identifiers i and j, the checksum is calculated as C(i, j) = i mod j + j mod i. Calculate the sum of C(i, j) for all pairs (1 <= i <= n) and (1 <= j <= n), where n is the total number of packets in the network. Return the result modulo (10 ** 9 + 7)
Complete the function computeChecksumAggregation in the editor.
computeChecksumAggregation has the following parameter:
int n: the total number of packets in the network
Returns
int: the aggregated checksum
My sincere thanks to da best friend for so generouly sharing the problem source! 🌷
1Example 1
Given n = 3, calculate the checksum for all the pairs of packets (i, j) where (1 <= i <= n) and (1 <= j <= n)
C(1, 1) = 1 mod 1 + 1 mod 1 = 0 + 0 = 0C(1, 2) = 1 mod 2 + 2 mod 1 = 1 + 0 = 1C(1, 3) = 1 mod 3 + 3 mod 1 = 1 + 0 = 1C(2, 1) = 2 mod 1 + 1 mod 2 = 0 + 1 = 1C(2, 2) = 2 mod 2 + 2 mod 2 = 0 + 0 = 0C(2, 3) = 2 mod 3 + 3 mod 2 = 2 + 1 = 3C(3, 1) = 3 mod 1 + 1 mod 3 = 0 + 1 = 1C(3, 2) = 3 mod 2 + 2 mod 3 = 1 + 2 = 3C(3, 3) = 3 mod 3 + 3 mod 3 = 0 + 0 = 0
The aggregated checksum is 0 + 1 + 1 + 1 + 0 + 3 + 1 + 3 + 0 = 10 mod (10 ** 9 + 7) = 10
Constraints
Limits and guarantees your solution can rely on.
1 <= n <= 10 ** 6