设 (cnt_i) 为 (i) 的出现次数。
则这题要求的是 (sum_{i=1}^{N} sum_{j=1}^{N} lcm(i, j) imes cnt_i imes cnt_j)
(left( lcm (i,j) = frac{ij}{gcd(i,j)} ight))
(sum_{i=1}^{N} sum_{j=1}^{N} frac{ij}{gcd(i,j)} imes cnt_i imes cnt_j)
枚举 (gcd)。
(sum_{d=1}^{N} sum_{i=1}^{N/d} sum_{j=1}^{N/d} [gcd(i,j) =1]d imes ij imes cnt_{id} imes cnt_{jd})
(sum_{k|n} mu_k = [n==1])
(sum_{d=1}^{N} sum_{i=1}^{N/d} sum_{j=1}^{N/d} sum_{k|gcd(i,j)}mu_k imes d imes ij imes cnt_{id} imes cnt_{jd})
枚举 (k)。
(sum_{d=1}^{N} sum_{k=1}^{N/d}sum_{i=1}^{n/kd}sum_{j=1}^{n/kd}mu_k imes d imes k^2 imes i imes j imes cnt_{idk} imes cnt_{jdk})
(T = dk)。
(sum_{T=1}^{N} T imes left(sum_{i=1}^{N/T} i imes cnt_{iT} ight)^2 sum_{k|T} mu_k imes k)
然后就做完了。