【容斥原理】Codeforces Round #428 (Div. 2) D. Winter is here
给你一个序列,让你对于所有gcd不为1的子序列,计算它们的gcd*其元素个数之和。
设sum(i)为i的倍数的数的个数,可以通过容斥算出来。
具体看这个吧:http://blog.csdn.net/jaihk662/article/details/77161436。
注意1*C(n,1)+2*C(n,2)+...+n*C(n,n)=n*2^(n-1)。
#include<cstdio>
using namespace std;
typedef long long ll;
#define MOD 1000000007ll
int n;
int a[200005],cnt[1000005];
ll sum[1000005],ans,pw[1000005];
int main(){
pw[0]=1;
for(int i=1;i<=1000000;++i){
pw[i]=(pw[i-1]*2ll)%MOD;
}
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
++cnt[a[i]];
}
for(int i=1000000;i>=2;--i){
int all=cnt[i];
for(int j=i*2;j<=1000000;j+=i){
sum[i]=(sum[i]+MOD-sum[j])%MOD;
all+=cnt[j];
}
sum[i]=(sum[i]+((ll)all*pw[all-1])%MOD)%MOD;
ans=(ans+((ll)i*sum[i])%MOD)%MOD;
}
printf("%I64d\n",ans);
return 0;
}
【容斥原理】Codeforces Round #428 (Div. 2) D. Winter is here的更多相关文章
- Codeforces Round #428 (Div. 2) D. Winter is here 容斥
D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
- CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...
- CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- 【Codeforces Round #428 (Div. 2) C】Journey
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...
- Codeforces Round #428 (Div. 2)A,B,C
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- github: Permission denied (publickey). 问题解决方法
部署服务器过程中想clone自己github中的库,结果出现Permission denied (publickey).的错误,解决方法是添加服务器公钥到github的settings->SSH ...
- 【Zigbee技术入门教程-02】一图读懂ZStack协议栈的核心思想与工作机理
[Zigbee技术入门教程-02]一图读懂ZStack协议栈的核心思想与工作机理 广东职业技术学院 欧浩源 Z-Stack协议栈是一个基于任务轮询方式的操作系统,其任务调度和资源分配由操作系统抽 ...
- bzoj 1058 bst
因为是数列的维护,所以我们可以考虑用splay来维护,每次在x插入的时候就在x+1前面插入就行了,然后用bst来维护两问的答案,但是应该会tle.我们来考虑这个问题的性质,首先因为这个数列没有删除操作 ...
- 加overflow-hidden就可以解决高度塌陷问题,overflow-触发BFC
1.BFC 全称是块级排版上下文,用于对块级元素排版,默认情况下只有根元素(body)一个块级上下文,但是如果一个块级元素 设置了float:left,overflow:hidden或position ...
- linux中的tasklet机制【转】
转自:http://blog.csdn.net/yasin_lee/article/details/12999099 转自: http://www.kerneltravel.net/?p=143 中断 ...
- 移动端测试===Android内存泄露和GC机制(转)
本文转自:https://www.testwo.com/article/1153 1.前言 Hello,小伙伴们,相信大家在项目测试中都遇到过内存泄露问题,小编也着实爬过很多坑.比如小编所测项目,更换 ...
- 【bzoj4562】HAOI2016食物链
记忆化搜索水过去了…… QwQ #include<bits/stdc++.h> #define N 400010 typedef long long ll; using namespace ...
- bzoj 1798 维护序列seq
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1798 题解: 高级一点的线段树,加上了区间乘法运算,则需要增加一个数组mulv记录乘的因数 ...
- service XXX start启动报start: Rejected send message, 1 matche
转,原文地址:http://blog.sina.com.cn/s/blog_56d8ea9001018w1l.html [问题]start: Rejected send messag现象:crifan ...
- jmeter压力测试案例实战
1. 测试目标地址:http://www.cnblogs.com/ 2. 1秒内有100个用户同时访问,看性能如何 3. 步骤 线程组.http请求.查看结果树.聚合报告 添加http请求如下: ...