博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #428 (Div. 2) D. Winter is here 容斥
阅读量:5945 次
发布时间:2019-06-19

本文共 1737 字,大约阅读时间需要 5 分钟。

D. Winter is here

题目连接:

Description

Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers.

He has created a method to know how strong his army is. Let the i-th soldier’s strength be ai. For some k he calls i1, i2, ..., ik a clan if i1 < i2 < i3 < ... < ik and gcd(ai1, ai2, ..., aik) > 1 . He calls the strength of that clan k·gcd(ai1, ai2, ..., aik). Then he defines the strength of his army by the sum of strengths of all possible clans.

Your task is to find the strength of his army. As the number may be very large, you have to print it modulo 1000000007 (109 + 7).

Greatest common divisor (gcd) of a sequence of integers is the maximum possible integer so that each element of the sequence is divisible by it.

Input

The first line contains integer n (1 ≤ n ≤ 200000) — the size of the army.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000000) — denoting the strengths of his soldiers.

Output

Print one integer — the strength of John Snow's army modulo 1000000007 (109 + 7).

Sample Input

3

3 3 1

Sample Output

12

Hint

题意

让你考虑所有gcd大于1的集合。这个集合的贡献是gcd乘上集合的大小。

问你总的贡献是多少。

题解:

令cnt[i]表示因子含有i的数的个数

\(f(i)=1*C(cnt[i],1)+2*C(cnt[i],2)+...+cnt[i]*C(cnt[i],cnt[i])\)
那么ans[i]=f(i)*2^(cnt[i]-1)-f(2i)-f(3i)-....
ans[i]表示gcd为i的答案

代码

#include
using namespace std;const int maxn = 1e6+7;const int mod = 1e9+7;long long p[maxn],w[maxn];long long cnt[maxn];long long a[maxn];int n;int main(){ p[0]=1; for(int i=1;i
>n; for(int i=1;i<=n;i++){ cin>>a[i]; cnt[a[i]]++; } long long ans = 0; for(int i=2;i

转载地址:http://ktwxx.baihongyu.com/

你可能感兴趣的文章
PHP array_key_exists() 函数(判断某个数组中是否存在指定的 key)
查看>>
Charpter5 软件测试总结
查看>>
python中@staticmethod、@classmethod和实例方法
查看>>
Java创建数组的三种方法
查看>>
管理计算机内存
查看>>
some requirement checks failed
查看>>
存储管理
查看>>
HDU-2089-不要62
查看>>
供应商接口的使用
查看>>
Latex学习笔记0
查看>>
css控制div强制换行
查看>>
ios 底部用定位 fixed。在软件盘出来后,页面元素被顶上去一部分,fixed定位的footer也跑到了上面去。解决方法...
查看>>
HDU1257题解
查看>>
Iterator
查看>>
Spring MVC整合Velocity
查看>>
fiddler+android抓包工具配置使用
查看>>
Spring Data JPA 复杂/多条件组合分页查询
查看>>
css文本 颜色1
查看>>
博客搬家了
查看>>
JavaScript中的作用域,闭包和上下文
查看>>