Codeforces 839D Winter is here
来源:互联网 发布:win7电脑桌面美化软件 编辑:程序博客网 时间:2024/06/04 23:42
转载请注明出处,谢谢http://blog.csdn.net/bigtiao097?viewmode=contents
题意:
给一个长度为n
思路:
枚举gcd的值x,对于每一个x,统计一下在序列中有多少个元素时x的倍数,这里可以开一个桶,将读入序列存入,这样可以将复杂度降至
这个式子的值为
但是这样还有一个问题就是,比如说x=2时,假设数列中有元素4、8,这样4和8的gcd为4而不是2,我们应该想办法去掉这种情况具体做法如下:
在枚举到x的时候,我们统计出m,计算出
具体代码如下:
Result:Accepted Memory: 13600 KB Time : 249 ms
#include<cstdio>const int maxn=1e6+5;const int mod =1e9+7;int n,x,ans;int pow[maxn],a[maxn],f[maxn];int main(){ scanf("%d",&n); pow[0] = 1; for(int i=1; i<=n; i++) pow[i]=2*pow[i-1]%mod; for(int i=1; i<=n; i++) { scanf("%d",&x); a[x]++; } for(int i=maxn-1; i>1; i--) { x = 0; for(int j=i; j<maxn; j+=i) x+=a[j]; if(x) { f[i]=1LL*x*pow[x-1]%mod; for(int j=i+i; j<maxn; j+=i) f[i]=(f[i]-f[j]+mod)%mod; ans=(1LL*f[i]*i+ans)%mod; } } printf("%d",ans);}
阅读全文
0 0
- codeforces 839 D Winter is here
- Codeforces 839D Winter is here
- codeforces 839d Winter is here
- Codeforces 839D-Winter is here
- CodeForces 839D Winter is here(数学 容斥)
- Codeforces 839D Winter is here【容斥原理+数学公式】
- Codeforces 839 D. Winter is here 容斥
- Codeforces-839D Winter is here(容斥原理)
- Winter is here codeforces 839d 容斥
- CodeForces 839D Winter is here (容斥原理)
- Codeforces Round #428 (Div. 2) D. Winter is here
- Codeforces-822D Winter is here(DP)
- Codeforces 839 D. Winter is here (莫比乌斯反演)
- Codeforces 839D Winter is here 组合数公式/容斥
- CodeForces Round 428 div2 839D Winter is here(数学)(详解)
- [容斥] Codeforces#428 (Div. 2) 839D. Winter is here
- 【Codeforces 839D. Winter is here】& 莫比乌斯反演
- Codeforces Round #428 (Div. 2) D. Winter is here(容斥,补题)
- 利用KNN算法实现手写体数字的识别
- GPIO
- Spark基础-Scala条件判断和循环
- 简易的多组数据题模板
- codeforces #428 Div.2 B. Game of the Rows 贪心、思维
- Codeforces 839D Winter is here
- composer简介
- JAVA之面向对象
- Hibernate一级缓存
- Spring_HelloWorld
- Java虚拟机--类加载机制
- 用canvas标签实现网页H5动态时钟
- SSM WebSocket项目搭建
- 去噪自编码网络-Python Keras实现