Gym 101992D The Millennium Prize Problems

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 = 1 n ∑ j = 1 n L C M ( A i , A j ) \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}LCM(A_i,A_j) i=1nj=1nLCM(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
这题也许算比较经典?
其实就是要枚举值域来求。
记值域上界为 N N N c n t x cnt_x cntx x x x 出现的次数

∑ i = 1 n ∑ j = 1 n L C M ( A i , A j ) = ∑ i = 1 N ∑ j = 1 N L C M ( i , j ) ∗ c n t i ∗ c n t j = ∑ i = 1 N ∑ j = 1 N i ∗ j g c d ( i , j ) ∗ c n t i ∗ c n t j \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_j i=1nj=1nLCM(Ai,Aj)=i=1Nj=1NLCM(i,j)cnticntj=

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值