description
Did you hear about the Millennium Prize Problems? They are seven problems in mathematics that were stated by the Clay Mathematics Institute on May 24, 2000. A correct solution for any of these problems results in a million dollar prize being awarded by the institute to the discoverer(s).
Soliman, one of the ECPC judges came up with a new mathematics problem and claimed that it should be the eighth Millennium Prize Problem as he is pretty sure no one could solve it. Here’s the problem:
Given an array A of length N (the array can have duplicate values). What is the sum of all least common multiple (LCM) values for every pair of the array? More formally you need to calculate the following:
∑i=1n∑j=1nLCM(Ai,Aj)\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}LCM(A_i,A_j)i=1∑nj=1∑nLCM(Ai,Aj)
Tefa, one of the ECPC judges suggested that we can add it in the problem set to see if someone can come up with a solution, so can you do it?
Input
The first line of the input contains a single integer T the number of test cases, each test case consists of one line containing N+1 space-separated integers, the first integer is the number N the size of the array and the remaining integers are the elements of the array A, where 1≤N≤105 and 1≤Ai≤105.
Output
For each test case output the answer to the problem modulo 109+7.
Example
Input
2
4 2 6 12 15
5 2 3 7 11 12
Output
335
861
分析
好久没做莫比乌斯函数题了,来一发hhh
这题也许算比较经典?
其实就是要枚举值域来求。
记值域上界为 NNN,cntxcnt_xcntx 为 xxx 出现的次数
∑i=1n∑j=1nLCM(Ai,Aj)=∑i=1N∑j=1NLCM(i,j)∗cnti∗cntj=∑i=1N∑j=1Ni∗jgcd(i,j)∗cnti∗cntj\sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}LCM(A_i,A_j) = \sum\limits_{i=1}^{N}\sum\limits_{j=1}^{N}LCM(i,j)*cnt_i*cnt_j=\sum\limits_{i=1}^{N}\sum\limits_{j=1}^{N}\dfrac{i*j}{gcd(i,j)}*cnt_i*cnt_ji=1∑nj=1∑nLCM(Ai,Aj)=i=1∑Nj=1∑NLCM(i,j)∗cnti∗cntj=i=1∑Nj=

这篇博客介绍了关于 Millennium Prize Problems 的一个新数学问题,涉及计算数组中所有对的最小公倍数之和。作者提供了一个输入输出示例,并分析了解决该问题的方法,包括利用莫比乌斯函数和预处理计算。最后给出了解决问题的代码思路,复杂度为 O(nlogn)。
最低0.47元/天 解锁文章
1337

被折叠的 条评论
为什么被折叠?



