[Codeforces Round #428 DIV2D (CF839D)] Winter is here
来源:互联网 发布:天极软件中心 编辑:程序博客网 时间:2024/06/05 23:44
题意
给定一个数列
题解
考虑枚举
当
由基础的组合数学知识得上式的结果为
当
如果直接枚举因子减去多出的贡献,复杂度
从小到大枚举
代码
/// by ztx/// blog.csdn.net/hzoi_ztx#include <bits/stdc++.h>#define Rep(i,l,r) for(i=(l);i<=(r);i++)#define rep(i,l,r) for(i=(l);i< (r);i++)#define Rev(i,r,l) for(i=(r);i>=(l);i--)#define rev(i,r,l) for(i=(r);i> (l);i--)#define Each(i,v) for(i=v.begin();i!=v.end();i++)#define r(x) read(x)typedef long long ll ;typedef double lf ;int CH , NEG ;template <typename TP>inline void read(TP& ret) { ret = NEG = 0 ; while (CH=getchar() , CH<'!') ; if (CH == '-') NEG = true , CH = getchar() ; while (ret = ret*10+CH-'0' , CH=getchar() , CH>'!') ; if (NEG) ret = -ret ;}template<typename TP>inline bool MI(TP&a,const TP&b){return a>b?a=b,true:false;}template<typename TP>inline bool MA(TP&a,const TP&b){return a<b?a=b,true:false;}#define kN 200010LL#define mod 1000000007LL#define kA 1000010LLinline void inc(int&a,const int&b) {a+=b;if(a>=mod)a-=mod;}inline void dec(int&a,const int&b) {a-=b;if(a<0)a+=mod;}int n, ans = 0, ma = 1;int cnt[kA], pow_2[kN], gcd[kA];int main() { int i, j, now; r(n); Rep (i,1,n) r(j), cnt[j] ++ , MA(ma,j); pow_2[0] = 1; Rep (i,1,n) pow_2[i] = pow_2[i-1], inc(pow_2[i],pow_2[i-1]); Rep (i,2,ma) for (gcd[i]+=i, j=i<<1; j <= ma; j += i) dec(gcd[j],gcd[i]); Rep (i,2,ma) { for (now=0, j=i; j <= ma; j += i) now += cnt[j]; if (!now) continue; inc(ans,1LL*now*gcd[i]%mod*pow_2[now-1]%mod); } printf("%d\n", ans); END: getchar(), getchar(); return 0;}
阅读全文
0 0
- [Codeforces Round #428 DIV2D (CF839D)] 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
- Codeforces Round #428 (Div. 2):D. Winter is here(组合数公式)
- CodeForces Round 428 div2 839D 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(组合数公式)
- CF——Codeforces Round #428 (Div. 2)D. Winter is here
- codeforces 839 D Winter is here
- Codeforces 839D Winter is here
- codeforces 839d Winter is here
- Codeforces 839D-Winter is here
- Codeforces839D Winter is here
- [容斥] Codeforces#428 (Div. 2) 839D. Winter is here
- CodeForces 839D Winter is here(数学 容斥)
- Codeforces 839D Winter is here【容斥原理+数学公式】
- HDU 1009 FatMouse' Trade
- scikit-learn中PCA的使用方法
- vim入门小技巧
- java 程序员成长的几大成长法则
- 网络流之最大流
- [Codeforces Round #428 DIV2D (CF839D)] Winter is here
- MongoDb的普通查询操作
- python3 操作字符串的基本函数
- 技术人生的职场众生相
- Gym 101341C Urn with Balls 签到
- 【总结】强连通分量
- SSH
- 一个DEA程序模板
- 【英语】程序员,你应该懂一些英语