Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
来源:互联网 发布:动画短片制作软件 编辑:程序博客网 时间:2024/06/05 20:42
题目链接:http://codeforces.com/contest/839/problem/D
题意:给出一些数,求取出一些数,当他们的GCD大于1时,将数量乘GCD累加到答案上,
求累加和。
思路:枚举每个GCD,对于每个GCD考虑两点:
1.首先得到一个集合,这个集合里面的数都是GCD的倍数,设集合大小为N,这个时候GCD对于答案的贡献就是1*C(1,N)+2*C(2,N)+….+N*C(N,N),由于C(I,K)=C(K-I,K),原式就变为N/2*(C(0,N)+C(1,N)+C(3,N)…+C(N,N))=N/2*2^N;
2.这里面有多算的部分,比如gcd=2,set={2,4,8},而gcd(4,8)=4,所以还要减去gcd=4,8,16…..的情况,反过来容斥一遍就好。
#include<bits/stdc++.h>using namespace std;const int MAXN=1000010,MOD=1e9+7;int y[MAXN],pw[MAXN],dp[MAXN];int main(){ int z,mx,n,i; mx=-1; scanf("%d",&n); for(pw[0]=1,i=1;i<=n+1;i++) pw[i]=2*pw[i-1]%MOD; int ans=0; for(int i=0;i<n;i++) scanf("%d",&z),y[z]++,mx=max(mx,z); for(int i=mx;i>1;i--) { z=0; for(int j=i;j<=mx;j+=i) z+=y[j]; if(z==0) continue; dp[i]=1ll*pw[z-1]*z%MOD; for(int j=i+i;j<=mx;j+=i) dp[i]=(dp[i]-dp[j]+MOD)%MOD; ans=(ans+1ll*i*dp[i])%MOD; } cout<<ans<<endl;}
阅读全文
0 0
- 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)
- jQuery学习笔记——jQuery选择器练习
- The AnimationClip 'xxx' used by the Animation component 'xxx' must be marked as Legacy.
- snapdragon camera menu控制与事件触发介绍
- okGo详细使用步骤(一)
- 字典树(前缀数)例题以及模板
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
- 五个方法成为更好的程序员
- 浏览器同源政策及其规避方法
- win10安装scrapy
- SQLSERVER 存储过程分页算法
- 如何更改CPropertySheet的背景色
- zookeeper的安装目录调整
- caffe安装系列——安装python依赖包
- 编译型语言与解释型语言简析