Codeforces Round #441 (Div. 2) D
来源:互联网 发布:ios付费软件推荐 编辑:程序博客网 时间:2024/05/22 08:27
题意
给你n个数
然后定义一个团队为选出若干个数,使得他们gcd不为1
然后一个团队的价值为,他们所有数的gcd乘上他们的人数
然后要你算出所有有可能的团队的和
题解
挺神的一道题。。反正我是不怎么会了。。要嘎爷爷带飞
然后怎么做呢?
我们考虑答案是怎么算的:
我们用一个数组,sum[i]表示gcd为i个序列长度和个数的总和
不难知道,答案就是
那么怎么算出这个sum[i]呢
先假设一个有公因数i的情况吧。。
我们定义,cnt[i]为有因数i的个数
然后可以得到
把一个cnt[i]提出来
我们可以发现,右式又形成了一个组合数。。公式太麻烦,不想打了
于是用二项式定义化简可得
然后当然,这有许多多算的,就是说i吧i的倍数也算上了,所以要减去他的倍数
于是就做完了
CODE:
#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>using namespace std;typedef long long LL;const LL MOD=1e9+7;const LL N=200005;const LL M=1000005;LL n;LL s[N];LL cnt[M];//这个因数有多少个人有bool in[M];LL f[M];LL get (LL x,LL y){ if (y==1) return x; if (y==0) return 1; LL lalal=get(x,y/2); lalal=lalal*lalal%MOD; if (y&1) lalal=lalal*x%MOD; return lalal;}LL dfs (LL x){ if (in[x]==true) return f[x]; in[x]=true; if (cnt[x]==0) {f[x]=0;return 0;} LL lalal=0; for (LL i=2;i*x<=1000000;i++) { lalal=lalal+dfs(i*x); if (lalal>=MOD) lalal-=MOD; } f[x]=((cnt[x]*get(2,cnt[x]-1)%MOD-lalal)%MOD+MOD)%MOD; return f[x];}int main(){ memset(in,false,sizeof(in)); scanf("%lld",&n); for (LL u=1;u<=n;u++) scanf("%lld",&s[u]); for (LL u=1;u<=n;u++) { for (LL i=2;i*i<=s[u];i++) if (s[u]%i==0) { cnt[i]++; if (i*i!=s[u]) cnt[s[u]/i]++; } cnt[s[u]]++; } for (LL u=2;u<=1000000;u++) dfs(u); LL ans=0; for (LL u=2;u<=1000000;u++) ans=(ans+u*f[u]%MOD)%MOD; printf("%lld\n",ans); return 0;}
阅读全文
0 0
- Codeforces Round #441 (Div. 2) D
- Codeforces Round #252 (Div. 2)441D. Valera and Swaps
- Codeforces Round #103 (Div. 2) D
- Codeforces Round #104 (Div. 2) D
- Codeforces Round #105 (Div. 2) D
- Codeforces Round #139 (Div. 2) D. Snake
- Codeforces Round #155 (Div. 2) D-rats
- Codeforces Round #159 (Div. 2) D sum
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round#186(Div 2) D
- codeforces Round # 187(Div.2) D
- Codeforces Round #191 (Div. 2) D
- Codeforces Round #194 (Div. 2) D. Chips
- Codeforces Round #209 (Div. 2) <A-D>
- Codeforces Round #218 (Div. 2) D. Vessels
- Codeforces Round #231 (Div. 2)A-D
- Codeforces Round #139 (Div. 2) D. Snake
- Codeforces Round #235 (Div. 2) A~D
- Xcode9学习笔记14
- 1996: [Hnoi2010]chorus 合唱队
- 090 定积分之物理应用
- BZOJ1040 [ZJOI2008]骑士
- 计算机比赛反思
- Codeforces Round #441 (Div. 2) D
- 2017.10.23.拓展欧几里得
- Cookie的基本概念及设置
- 1907: 树的路径覆盖
- Learning Spark笔记14-通过集群运行
- 【2767】2017年10月10日提高组T1 xjh的旅行
- python中字典操作II
- 1617: [Usaco2008 Mar]River Crossing渡河问题
- tableau计算字段编辑器中,字段名称不能正常显示。