Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
来源:互联网 发布:sql备份 编辑:程序博客网 时间:2024/06/05 15:55
转载出处:http://blog.csdn.net/jaihk662/article/details/77161436
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.
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.
Print one integer — the strength of John Snow's army modulo 1000000007 (109 + 7).
33 3 1
12
42 3 4 6
39
题意:
如果一个子序列的GCD为1,那么这个子序列的价值为0,否则子序列价值为子序列长度*子序列GCD
给出n个数,求这n个数所有子序列的价值和
题解:
考虑暴力每一个GCD,求出这个GCD对答案的贡献
如果枚举到x,n个数中有sum[x]个数是x的倍数,那么x对答案的贡献就是
但这可能会算重复,因为由全是x倍数组成的子序列它的GCD不一定是x啊
所以sum[x]还要减掉所有的sum[y],其中y为x的倍数
那么令val[x]为x对答案的贡献,就有
所以枚举GCD时要倒过来枚举
最后求一波和就是答案
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式) +容斥
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
- Codeforces Round #428 (Div. 2) D. Winter is here
- Codeforces Round #428 (Div. 2) D. Winter is here(容斥,补题)
- Codeforces Round #428 (Div. 2) D. Winter is here(序列元素个数*gcd
- CF——Codeforces Round #428 (Div. 2)D. Winter is here
- Codeforces 839D Winter is here 组合数公式/容斥
- [容斥] Codeforces#428 (Div. 2) 839D. Winter is here
- Codeforces Round #387 (Div. 2) D. Winter Is Coming
- Codeforces Round #387 (Div. 2) D. Winter Is Coming
- Codeforces Round #387 (Div. 2) D && coedeforces 744 D. Winter Is Coming(贪心)
- CodeForces Round 428 div2 839D Winter is here(数学)(详解)
- Codeforces Round #387 (Div. 2)D. Winter Is Coming(复杂贪心)
- [Codeforces Round #428 DIV2D (CF839D)] Winter is here
- Codeforces Round #387 (Div. 2) Winter Is Coming(贪心)
- Codeforces-822D Winter is here(DP)
- supervisor 杂记
- REST 应用编程接口
- Jquery的zTree--Js点击树节点
- Python 07(列表)
- Eclipse使用技巧小结
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
- PHP判断手机是IOS还是Android
- hdu 4458 Shoot the Airplane 点在平面内 相对运动
- P1349 广义斐波那契数列
- Vue.js知识总结 (一)
- 图的建立与查找
- leetcode 235. Lowest Common Ancestor of a Binary Search Tree
- 初学俄罗斯方块,完美注释--欢迎指出bug
- ArcGIS中QueryTask,FindTask,IndentifyTask 之间的区别