Codeforces Round #428 (Div. 2) ( 组合数学)
来源:互联网 发布:origin绘图软件下载 编辑:程序博客网 时间:2024/05/23 10:36
题目链接
题解:
组合数学:
Let cnt[i] be the number of such js that aj is divisible by i. Than cnt[i] is count of soliders with strength of i, 2i, 3i, ....
Let ans[i] be count of people in clans with gcd = i. To find ans[i] let's understand, how to find count of people in clans, in which every number is divided by i. If cnt[i] = c, it's
Let's calculate ans[i] from the end. Then ans[i] = cnt[i]·2cnt[i] - 1 - ans[2i] - ans[3i] - ....
Answer for problem's question is .
Asymptotics of solution is , where k is maximal value of ai.
ans[i]就是gcd为i的所有序列的元素个数之和,也就是题目中当gcd为d是的k之和。
代码如下:
#include <bits/stdc++.h>#define ll long longusing namespace std;const int maxn = 2e5 + 10;const int maxm = 1e6 + 10;const ll MOD = 1e9 + 7;ll ans[maxm],cnt[maxm];int a[maxn],n,vis[maxm];ll q_pow(ll x,int k){ll ret = 1;while(k > 0) {if(k & 1) ret = ret * x % MOD;x = x * x % MOD;k >>= 1;}return ret;}int main(){scanf("%d",&n);int maxv = 0;for(int i = 1;i <= n;i++){scanf("%d",&a[i]);maxv = max(maxv,a[i]);vis[a[i]]++;}cnt[1] = n;for(int i = 2;i <= maxv;i++){for(int j = i;j <= maxv;j+=i){cnt[i] += vis[j];}}ll out = 0;for(int i = maxv;i >= 1;i--){if(cnt[i] <= 0) continue;ans[i] = cnt[i] * q_pow(2,cnt[i] - 1) % MOD;for(int j = i + i;j <= maxv;j+=i){ans[i] = (ans[i] - ans[j] + MOD) % MOD;}if(i > 1) out = (ans[i] * i + out) % MOD;}printf("%I64d\n",out);}
阅读全文
0 0
- Codeforces Round #428 (Div. 2) ( 组合数学)
- Codeforces Round #384 (Div. 2)(数学)
- Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)
- Codeforces Round #340 (Div. 2)-B. Chocolate(组合数学的乘法计数)
- Codeforces Round #369 (Div. 2) D. Directed Roads (dfs+组合数学 图论)
- Educational Codeforces Round 33 (Rated for Div. 2) E. Counting Arrays(组合数学)
- Codeforces Round #448 (Div. 2)D. String Mark(组合数学)
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 1)(组合数学+容斥)
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- Codeforces 869C ( Codeforces Round #439 (Div. 2) ) The Intriguing Obsession 组合数学
- 【组合数学】 Codeforces Round #295 (Div. 1) C - Pluses everywhere
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya(组合数学)
- Codeforces Round #317 (Div. 2) 571A. Lengthening Sticks 组合数学
- Codeforces Round #324 (Div. 2) 584B. Kolya and Tanya 组合数学
- Codeforces Round #338 (Div. 2)D. Multipliers【费马小定理+组合数学】
- Codeforces Round #361 (Div. 2) 题解 粗鲁地二分 组合数学提炼模型
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp,组合数学
- 组合数学——Codeforces Round #404 (Div. 2) D. Anton and School
- [bzoj4517][Sdoi2016]排列计数 组合数+逆元
- Unity3D利用Photon实现实时联网对战(三)创建和加入房间
- 1065. 单身狗
- MAC & PHY
- javaScript中格式化日期毫秒数
- Codeforces Round #428 (Div. 2) ( 组合数学)
- JDK5以后的新特性---增强for循环,静态导入,可变参数
- js,html里unicode与ascii转换代码
- 微信小程序组件探究和应用
- Storm入门与实践(2)构建Storm的开发环境与集群
- 做视频直播时如何测试本地网络的上行带宽(网速测试)
- Openstack部署工具总结
- Spring data redis-StringRedisTemplate 用法
- Android 自定义View画圆