4662. 因数平方和 - AcWing题库(python)
# 输入
n = int(input())
mod =int(1e9 + 7)
# 求平方和
def square_sum(n):
return n * (n + 1) * (2 * n + 1) // 6 % mod
# 结果
res = 0
i=1
while(i<=n):
# 找到开始跟结尾
x = n // i
y = n // xres = (res + (square_sum(y) - square_sum(i - 1)) * x) % mod
i=y+1
print((res+mod)%mod)