Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式) +容斥
来源:互联网 发布:北京市相对湿度数据 编辑:程序博客网 时间:2024/06/05 05:32
参考http://m.blog.csdn.net/Hallelujah520/article/details/77164467
和http://m.blog.csdn.net/Hallelujah520/article/details/77164467
要容斥是因为这个地方算的是组合数的公式,所以有些地方的gcd是4,不是2的情况
差的地方:
1:这个地方的公式不会推。。
2:对于这个地方的容斥,想不到还能这样处理,而且这个复杂度不会爆。。。
不敲了,直接复制别人的代码。。
#include<stdio.h> #define mod 1000000007 #define LL long long LL cnt[1000005], sum[1000005]; LL Pow(LL a, LL b) { LL now; now = 1; while(b) { if(b%2) now = now*a%mod; a = a*a%mod; b /= 2; } return now; } int main(void) { LL ans, i, j, n, x; scanf("%lld", &n); for(i=1;i<=n;i++) { scanf("%lld", &x); cnt[x]++; } ans = 0; for(i=1000000;i>=2;i--) { x = 0; for(j=i;j<=1000000;j+=i) { sum[i] -= sum[j]; x += cnt[j]; } sum[i] += x*Pow(2, x-1)%mod; ans = ((ans+sum[i]*i)%mod+mod)%mod; } printf("%lld\n", ans); return 0; }
阅读全文
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 839D Winter is here 组合数公式/容斥
- Codeforces Round #428 (Div. 2) D. Winter is here
- [容斥] Codeforces#428 (Div. 2) 839D. Winter is here
- Codeforces-839D Winter is here(容斥原理)
- CodeForces 839D 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 839D Winter is here【容斥原理+数学公式】
- Codeforces 839 D. Winter is here 容斥
- Winter is here codeforces 839d 容斥
- Codeforces Round #387 (Div. 2) D. Winter Is Coming
- Codeforces Round #387 (Div. 2) D. Winter Is Coming
- Java攻城狮面试题(-)
- Android-25种开源炫酷动画框架
- HDU 5835 Danganronpa
- RDC容器构建和部署服务新功能上线
- Hibernate Validator 方法界别验证,通过AOP实现,Unable to initialize 'javax.el.ExpressionFactory'.
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式) +容斥
- 批量上传 Jar 包到 Maven 私服的工具
- .net用QrCodeNet来生成二维码
- scala implicit class使用
- 句柄啊句柄!
- 随机生成验证码
- apt-get update 出现“Sub-process returned an error code”错误
- 欢迎使用CSDN-markdown编辑器
- 细粒度权限管理