codeforces 864D 莫比乌斯反演
来源:互联网 发布:和服羽织淘宝 编辑:程序博客网 时间:2024/06/05 09:20
简略题意:给出
枚举
令
假若有
而
#include <bits/stdc++.h>using namespace std;typedef long long LL;const LL maxn = 1100000;const LL mod = 1e9+7;LL mul(LL a, LL b) { a *= b; a = a % mod; a += mod; a %= mod; return a;}LL add(LL a, LL b) { a += b; if(a >= mod) a-=mod; return a;}bool tag[maxn];LL p[maxn/10];LL mob[maxn]; //莫比乌斯线性筛LL cnt;void GetPrime(){ cnt = 0; mob[1] = 1; for(LL i = 2; i < maxn; i++){ if(!tag[i]) { p[cnt++] = i; mob[i] = -1; } for(LL j = 0; j < cnt && p[j] * i < maxn; j++){ tag[i * p[j]] = 1; if(i % p[j] == 0) { mob[i*p[j]] = 0; break; } mob[i*p[j]] = -mob[i]; } }}LL F[maxn], f[maxn];struct ASSWECAN { LL n; LL cnt[maxn]; LL pow2[maxn]; LL ans[maxn]; void solve() { scanf("%d", &n); for(LL i = 1; i <= n; i++) { LL v; scanf("%d", &v); cnt[v]++; } GetPrime(); pow2[0] = 1; for(LL i = 1; i <= 1000000; i++) pow2[i] = mul(pow2[i-1], 2); for(LL i = 2; i <= 1000000; i++) { LL s = 0; for(LL j = i; j <= 1000000; j+=i) s += cnt[j]; if(s) { F[i] = mul(s, pow2[s-1]); } } for(LL i = 1; i <= 1000000; i++) { for(LL j = i; j <= 1000000; j+=i) f[i] = add(mul(mob[j/i], F[j]), f[i]); } LL res = 0; for(LL i = 2; i <= 1000000; i++) res = add(res, mul(f[i], i)); printf("%lld\n", res); }} solver;int main(){ solver.solve(); return 0;}
阅读全文
0 0
- codeforces 864D 莫比乌斯反演
- Codeforces 839 D. Winter is here (莫比乌斯反演)
- 【Codeforces 839D. Winter is here】& 莫比乌斯反演
- 839D(容斥 || 莫比乌斯反演)
- Codeforces 645F Cowslip Collections (莫比乌斯反演)
- Codeforces 235E Number Challenge (莫比乌斯反演)
- Codeforces 235 E Number Challenge(莫比乌斯反演)
- codeforces 645F (莫比乌斯反演)
- 二项式反演,莫比乌斯反演。
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- 莫比乌斯反演
- NTP协议与计算
- 优秀网页设计
- Android SDK下载安装及配置教程
- 简单的事件分发机制
- 开源地图MapBox自定义(一):搭建环境
- codeforces 864D 莫比乌斯反演
- php学习笔记(二十三)PDO的预处理语句的查询以及结果集的使用
- sql,with as ,in的配合使用
- 第8章_图论
- 机器学习:线性回归与Python代码实现
- 【POCO】POCO学习总结(三)——交叉编译
- jsp页面response重定向
- spring boot -- mysql断连
- chrome 下一段代码的理解