def computeChecksumAggregation(n):
MOD = 1_000_000_007
# We need to calculate S' = Σ_{i=1 to n} Σ_{j=1 to n} (i mod j)
# The final answer will be (2 * S') % MOD
s_prime = 0
# We compute S' by swapping the summation order:
# S' = Σ_{j=1 to n} ( Σ_{i=1 to n} (i mod j) )
for j in range(1, n + 1):
# Calculate the inner sum: Σ_{i=1 to n} (i mod j)
# Number of full cycles of remainders (0, 1, ..., j-1)
num_cycles = n // j
# Length of the final, partial cycle
remainder_len = n % j
# --- Sum from full cycles ---
# The sum of one full cycle of remainders (1, ..., j) is
# 1%j + 2%j + ... + j%j = 1 + 2 + ... + (j-1) + 0 = j*(j-1)/2
# Since j*(j-1) is always even, we can divide by 2 before taking the modulo.
if j % 2 == 0:
term1 = (j // 2) % MOD
term2 = (j - 1) % MOD
else:
term1 = j % MOD
term2 = ((j - 1) // 2) % MOD
sum_one_cycle = (term1 * term2) % MOD
sum_from_cycles = ((num_cycles % MOD) * sum_one_cycle) % MOD
# --- Sum from the remaining part ---
# The sum of remainders for the final partial cycle is
# 1%j + 2%j + ... + (n%j)%j = 1 + 2 + ... + (n%j) = (n%j)*(n%j+1)/2
if remainder_len % 2 == 0:
term1_rem = (remainder_len // 2) % MOD
term2_rem = (remainder_len + 1) % MOD
else:
term1_rem = remainder_len % MOD
term2_rem = ((remainder_len + 1) // 2) % MOD
sum_from_remainder = (term1_rem * term2_rem) % MOD
# Add the sum for this j to the total s_prime
inner_sum_j = (sum_from_cycles + sum_from_remainder) % MOD
s_prime = (s_prime + inner_sum_j) % MOD
# The final aggregated checksum is 2 * s_prime
total_aggregated_checksum = (2 * s_prime) % MOD
return total_aggregated_checksum
print(computeChecksumAggregation(2))
print(computeChecksumAggregation(3))