Codeforces Round #428 (Div. 2) D. Winter is here
2017-08-13 20:34
423 查看
题目:http://codeforces.com/contest/839/problem/D
题意:找出所有gcd>1的集合,strength 为集合大小*gcd,计算所有的strength
思路:
![](http://img.blog.csdn.net/20170813203347694?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaHVhdGlhbjU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
代码:
题意:找出所有gcd>1的集合,strength 为集合大小*gcd,计算所有的strength
思路:
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD = 1e9+7; const int N = 1e6; int n,x; ll a[N+5],b[N+5],p[N+5]; void solve() { for(int i = 2;i <= N;i++) p[i] = i; for(int i = 2;i <= N;i++) for(int j = i*2;j <= N;j += i) p[j] -= p[i]; ll ans = 0,num = 0; for(int i = 2;i <= N;i++) { num =0; for(int j = i;j <= N;j+=i) num += a[j]; if(!num) continue; ans = (ans + ((num * b[num-1]) % MOD * p[i])% MOD )% MOD; } printf("%lld\n",ans); } int main() { scanf("%d",&n); for(int i = 1;i <= n;i++) { scanf("%d",&x); a[x]++; } ll y = 1;//2的n次幂 for(int i = 0;i <= N;i++) { b[i] = y; y = y*2 % MOD; } solve(); return 0; }
相关文章推荐
- (容斥)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(序列元素个数*gcd
- 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(序列元素个数*gcd
- 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 (Div. 2) D. Winter is here(序列元素个数*gcd
- CF——Codeforces Round #428 (Div. 2)D. Winter is here
- Codeforces Round #428 (Div. 2) D. Winter is here(序列元素个数*gcd
- [Codeforces Round #428 DIV2D (CF839D)] Winter is here
- Codeforces Round #428 (Div. 2) D. Winter is here(序列元素个数*gcd
- Codeforces Round #428 (Div. 2) D. Winter is here(序列元素个数*gcd
- 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(序列元素个数*gcd