CodeForces839D[莫比乌斯反演] Codeforces Round #428 (Div. 2)
/*CodeForces839D[莫比乌斯反演]*/
#include <bits/stdc++.h>
typedef long long LL;
const LL MOD = 1000000007LL;
using namespace std;
int n, maxa = , mina = 0x3f3f3f3f;
LL m[], F[], f[];
int sum[], a[];
int prime[], vis[], mu[];
void mo_init(int N) {
memset(vis, , sizeof(vis));
mu[] = ;
int cnt = ;
for (int i = ; i < N; i++)
{
if (!vis[i])
{
prime[cnt++] = i;
mu[i] = -;
}
for (int j = ; j < cnt && i * prime[j] < N; j++)
{
vis[i * prime[j]] = ;
if (i % prime[j]) mu[i * prime[j]] = -mu[i];
else
{
mu[i * prime[j]] = ;
break;
}
}
}
}
void solve() {
for (int i = ; i < n; i++) {
for (int j = ; j * j <= a[i]; j++) {
if (a[i] % j == ) {
if (j * j == a[i]) {
sum[j]++;
}
else {
sum[j]++, sum[a[i] / j]++;
}
}
}
}
LL ans = ;
for (int i = ; i <= maxa; i++) {
F[i] = sum[i] * m[sum[i] - ] % MOD;
}
for (int i = ; i <= maxa; i++) {
for (int j = i; j <= maxa; j += i) {
f[i] = (f[i] + mu[j / i] * F[j] % MOD) % MOD;
}
ans = (ans + f[i] * i % MOD) % MOD;
}
printf("%lld\n", ans);
}
void init() {
mo_init();
m[] = 1LL;
for (int i = ; i <= n; i++) {
m[i] = m[i - ] * 2LL % MOD;
}
}
int main() {
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &a[i]);
maxa = max(maxa, a[i]);
mina = min(mina, a[i]);
} init(), solve();
return ;
}
CodeForces839D[莫比乌斯反演] Codeforces Round #428 (Div. 2)的更多相关文章
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
- CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #i ...
- CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- Codeforces Round #428 (Div. 2) D. Winter is here 容斥
D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- 【Codeforces Round #428 (Div. 2) C】Journey
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...
- Codeforces Round #428 (Div. 2)A,B,C
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- CF Gym 100463D Evil (二维前缀和+离散)
题意:给一些带颜色的点,求一个最小的矩形,恰好包括一半的红色点,且不包括蓝色点. 题解:暴力,求个二维前缀和,用容斥原理更新一下.N很小所以我采用了离散优化,跑了个0ms. 之前没写过二维前缀和,加上 ...
- Robot Framework(一)入门
1.1简介 Robot Framework是一个基于Python的,可扩展的关键字驱动的测试自动化框架,用于端到端验收测试和验收测试驱动开发(ATDD).它可用于测试分布式异构应用程序,其中验证需要涉 ...
- python_86_shutil模块
#高级的文件.文件夹.压缩包.处理模块 import shutil f1=open('sys模块.py','r',encoding='utf-8') f2=open('copy1.py','w',en ...
- GC执行finalize的过程以及对象的一次自我拯救
参考资料:深入理解java虚拟机 /** * 此代码演示了两点: * 1.对象可以在被GC时自我拯救 * 2.这种自救的机会只有一次,因为一个对象的finalize()方法只会被系统自动调一次 */ ...
- DROP OPERATOR CLASS - 删除一个操作符类
SYNOPSIS DROP OPERATOR CLASS name USING index_method [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP OPER ...
- 如何将字符串@“ abc123.xyz789”倒置
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { ...
- NOIP2016 toy
题目描述 小南有一套可爱的玩具小人, 它们各有不同的职业. 有一天, 这些玩具小人把小南的眼镜藏了起来. 小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的面朝圈外.如下图: 这时singer告诉 ...
- CPL学习笔记(二)
数组 数组(array) 声明通用格式为: typeName arrayName[arraySize]. arrayName指定元素数目,必须为整型常量或const值.(不能是变量) int a[3] ...
- 【MySql】Mysql ERROR 1067: Invalid default value for ‘date’ 解决
在给一个表添加字段的时候,忽然发现会报一个date类型的字段的默认值错误,郁闷~ 经过排查,原来是MySQL的配置问题,在wamp下,MySQL 5.7里是没有设置 SQL_MODE 的. 1.my. ...
- 分割catalina.out 每天生成一个文件
1. touch xxx(文件名字).sh 2. vim xxx.sh 写入 ----------------------- #!/bin/sh cd `dirname $0`pwdd=`d ...