博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces 839D Winter is here【数学:容斥原理】
阅读量:6704 次
发布时间:2019-06-25

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

D. Winter is here

time limit per test:3 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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).

Examples
Input
3 3 3 1
Output
12
Input
4 2 3 4 6
Output
39
Note

In the first sample the clans are {1}, {2}, {1, 2} so the answer will be 1·3 + 1·3 + 2·3 = 12

题目链接:

 

下面给出AC代码:

1 #include
2 const int N=1000010,P=1000000007; 3 int n,i,j,x,ans,po[N],a[N],f[N]; 4 int main(){ 5 scanf("%d",&n); 6 for(po[0]=i=1;i<=n;i++)po[i]=2*po[i-1]%P; 7 while(n--)scanf("%d",&x),a[x]++; 8 for(i=N-1;i>1;i--){ 9 for(j=i,x=0;j

 

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

你可能感兴趣的文章
利用jQuery的deferred异步按顺序加载JS文件
查看>>
设计模式学习实践---策略模式(Strategy Pattern)
查看>>
AJAX 学习笔记[四] AJAX 对服务器返回的XML 的处理
查看>>
Caliburn.Micro学习笔记(二)----Actions
查看>>
python berkeley 操作——尤其提示 需版本匹配
查看>>
[浪子学编程][MS Enterprise Library]ObjectBuilder内功心法之中国特色
查看>>
android138 360 小火箭
查看>>
【转】WebService中使用自定义类的解决方法(5种)
查看>>
ASP.NET 页生命周期概述
查看>>
Xen虚拟机克隆实战
查看>>
HttpContext.Current.Session ,出现未将对象引用设置到实例上
查看>>
所谓深度链接(Deep linking)
查看>>
C#中的数据格式转换 (未完待更新)
查看>>
基于 Python 官方 GitHub 构建 Python 文档
查看>>
ArcSDE:C#创建SDE要素数据集
查看>>
arulesSequences包做序列模式的关联分析
查看>>
下面以Button组件为例,开始FLEX皮肤制作的入门。
查看>>
CSS学习(一)
查看>>
SQL Server 数据库安全
查看>>
Android双机(网络和USB)调试及其完美ROOT
查看>>